Write a program to find factorial of an entered number.
#include<stdio.h> unsigned long long Factorial(unsigned int); int main() { int num,i; unsigned long long Factorial_of_Number; printf("Enter Number = "); scanf("%d",&num); if(num > 0) { Factorial_of_Number = Factorial(num); for(i = num;i>1;i--) { printf("%2d x",i); } printf(" 1 = %llu\n",Factorial_of_Number); printf("\nFactorial of %d is = %llu\n",num,Factorial_of_Number); } else { printf("Factorial of %d doesn`t exist\n",num); } return 0; } unsigned long long Factorial(unsigned int n) { unsigned long long fact = 1; for(;n;n--) { fact = fact * n; } return fact; }
Output
Enter Number = 8 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = 40320 Factorial of 8 is = 40320
Enter Number = 15 15 x14 x13 x12 x11 x10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = 1307674368000 Factorial of 15 is = 1307674368000