Factorial Program in C | C program for Factorial of a Number
- 5! = 5*4*3*2*1 i.e 120
The value of 0! is 1, according to the convention for an empty product.
/***************Program*************/
1 |
#include<stdio.h><br />main()<br />{<br /> int n,fact=1,i;<br />Label: printf("Enter a Number :");<br /> scanf("%d",&n);<br /> if(n<0)<br /> {<br /> printf("No Factorial for Negative Non");<br /> goto Label;<br /> }<br /> else<br /> {<br /> if(n == 0)<br /> fact = 1;<br /> else<br /> {<br /> for(i=1;i<=n;i++)<br /> fact =fact*i;<br /> }<br /> }<br />printf("Factorial of %d is : %d..n",n,fact);<br />}<br /><br /> |
/*********** OUTPUT ***************/
1 |