C Program to Find Factorial of a Given Number
Question: Write a program in C to read a number from a user and then find factorial of that number.
Program
#include<stdio.h>
#include<conio.h>
int main()
{
long int i,n, f=1;
clrscr();
/* Input */
printf("Enter any positive integer: ");
scanf("%ld", &n);
/* Finding Factorial */
for(i=1;i<= n;i++)
{
f = f*i;
}
printf("%ld != %ld",n,f);
getch();
return(0);
}
Output of above program :
Enter any positive integer: 9 ↲ 9 != 362880 Note: ↲ indicates enter is pressed.