In mathematics,the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, 5 ! = 5 × 4 × 3 × 2 × 1 = 120.
#include <stdio.h>
int factorial(int num);
int main()
{
int num,fn;
printf("Enter the number :");
scanf("%d",&num);
fn=factorial(num);
printf("Factorial Number of %d is %d",num,fn);
printf("\nEnter another number :");
scanf("%d",&num);
fn=factorial(num);
printf("Factorial Number of %d is %d",num,fn);
return 0;
}
int factorial(int num)
{
int fn=1;
while(num>=1)
{
fn=fn*num;
num--;
}
return fn;
}
|
Enter the number :9 Factorial Number of 9 is 362880 Enter another number :12 Factorial Number of 12 is 479001600