bsc

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

root / semester_1 / tuition-c / P028.c

P028.c (572B)


      1 /* WAP to calculate factorial of a number */
      2 
      3 #include <stdio.h>
      4 int main()
      5 {
      6     int i = 1, num, fact = 1;
      7     printf("Enter the number : ");
      8     if (scanf("%d", &num) != 1)
      9     {
     10         printf("\nPlease enter a number.");
     11         return 1;
     12     }
     13     if (num == 0)
     14     {
     15         printf("\nFactorial of 0 : 1");
     16         return 0;
     17     }
     18     if (num < 0)
     19     {
     20         printf("\nFactorial of %d : UNDEFINED", num);
     21         return 0;
     22     }
     23     while (i <= num)
     24     {
     25         fact = fact * i;
     26         i++;
     27     }
     28     printf("Factorial of %d : %d", num, fact);
     29     return 0;
     30 }
© 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