bsc

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

root / semester_1 / letusc / lucproblem006.c

lucproblem006.c (838B)


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