Simple C Program to Find the Factorial of any Number :
Here's the code :
#include<stdio.h>
main()
{
int i,fact=1,num;
printf("Enter a number to find its factorial:\n");
scanf("%d",&num);
if(num<0)
{
printf("Please enter a number greater than zero");
}
else
{
for(i=1;i<=num;i++)
{
fact=fact*i;
}
printf("Entered number is %d and its factorial (%d!) is %d",num,num,fact);
}
}
#include<stdio.h>
main()
{
int i,fact=1,num;
printf("Enter a number to find its factorial:\n");
scanf("%d",&num);
if(num<0)
{
printf("Please enter a number greater than zero");
}
else
{
for(i=1;i<=num;i++)
{
fact=fact*i;
}
printf("Entered number is %d and its factorial (%d!) is %d",num,num,fact);
}
}
