Factorial of an integer is product of the number and all integers below it until 1.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1pvL3Bf3iqQk8ixpzrLcyubvua-jsRsWKER8UO18KvNuShlM_RqKng8NJ1nG02K11NRRO6k0YPsfFxr7aaCApafMQF8tGWZwR-RlTqS-0igWCYRL84aaqpVxaveqUkA-gBPcJn_Q9ZIQ/s320/fact.png)
5! = 5 * 4!
= 5 * 4 * 3!
= 5 * 4 * 3 * 2!
= 5 * 4 * 3 * 2 * 1!
= 5 * 4 * 3 * 2 * 1
Code
#include<stdio.h>
int main()
{
int fact=1,n,i;
printf("Enter a number ");
scanf("%d",&n);
for(i=n;i>=1;i--)
fact = fact * i;
printf("\nFactorial of %d = %d",n,fact);
return 0;
}
O/P
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1pvL3Bf3iqQk8ixpzrLcyubvua-jsRsWKER8UO18KvNuShlM_RqKng8NJ1nG02K11NRRO6k0YPsfFxr7aaCApafMQF8tGWZwR-RlTqS-0igWCYRL84aaqpVxaveqUkA-gBPcJn_Q9ZIQ/s320/fact.png)
No comments:
Post a Comment