Here is a simple C program to find the factorial of a number is given. The product of all numbers from 1 to that number by keeping difference one is called the factorial of the given number.For example 120 is the factorial of 5.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, The value of 0! is 1, according to the convention for an empty product.
Explanation:
5=1,2,3,4,5
120=1*2*3*4*5
NOTE : Factorial of 0 is always 1.
C program to find the factorial of a number
#include<stdio.h>
int main()
{
int i,num,fact=1;
printf("nEnter a number :");
scanf("%d",&num);
if(num==0)
printf("nFactorial of %d is %d",num,1);
else
{
for(i=1;i<=num;i++)
fact=fact*i;
printf("nFactorial of %d is %d",num,fact);
}
return 0;
}
Output : Enter a number: 6 Factorial of 6 is 720