Factorial of a number calculated by multiplying all the numbers up to a given number
Ex: 5!
to calculate 5! we need to multiply all the numbers under 5 till 1.
5*4*3*2*1 = 120
so, 5 factorial is 120.
#include<stdio.h> int main() { int i,n,factorial; printf(" Enter the number : "); scanf("%d",&n); factorial = 1; for(i=1; i<=n; i++) { factorial = factorial * i; } printf("\n Factorial of %d is %d",n,factorial ); return 0; }
OUTPUT:
Enter the number : 5 Factorial of 5 is 120
How to compute factorial of large number, it is not possible with the existing data types
Check out other programs
C Program to Find Factorial of a Number using Functions
C Program to Find Factorial of a Number using While Loop