pc008.c (535B)
1 /* Factorial upto N */ 2 3 #include <stdio.h> 4 5 int main() 6 { 7 int n, i; 8 long long fact = 1; 9 printf("Enter n : "); 10 if (scanf("%d", &n) != 1) 11 { 12 printf("\nOnly non-negative number allowed."); 13 return 1; 14 } 15 if (n < 0) 16 { 17 printf("\nOnly non-negative number allowed."); 18 return 1; 19 } 20 if (n == 0) 21 { 22 printf("\nFactorial of 0 : 1"); 23 return 0; 24 } 25 for (i = 1; i <= n; i++) 26 fact *= i; 27 printf("\nFactorial of %d : %lld", n, fact); 28 return 0; 29 }