bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

lucproblem006.c (974B)


      1 /*
      2  * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 12 Dec 2025
      3  * Repo: https://github.com/notamitgamer/bsc
      4  * License: MIT
      5  */
      6 
      7 /* Write a program to find the factorial value of any number entered
      8 through the keyboard. */
      9 /* Let Us C, Chap - 5, Page - 84, Problem 5.2 */
     10 
     11 #include <stdio.h>
     12 int main()
     13 {
     14     int num, i = 1;
     15     long long fact = 1;
     16     printf("Enter the number : ");
     17     // checking if the input is valid or not
     18     if (scanf("%d", &num) != 1)
     19     {
     20         printf("\nPlease enter a number.");
     21         return 1;
     22     }
     23     // result for the negetive input
     24     if (num < 0)
     25     {
     26         printf("\nFactorial of %d : Undefined", num);
     27         return 1;
     28     }
     29     //  Hard codded result for input '0' (zero)
     30     if (num == 0)
     31     {
     32         printf("\nFactorial of 0 : 1");
     33         return 0;
     34     }
     35     // calculating result
     36     while (i <= num) {
     37         fact = fact * i;
     38         i++;
     39     }
     40     printf("\nFactorial of %d : %d", num, fact);
     41     return 0;
     42 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror