In this program, you will learn how to find factorial of a number. The factorial of a number is the product of all the integers from 1 to that number. For example, the factorial of 4 (denoted as 4!) is 1*2*3*4 = 24. Factorial is not defined for negative numbers and the factorial of zero is one, 0! = 1 .
#include <stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int no, f;
//clrscr();
printf("Enter the number: ");
scanf("%d", &no);
f = fact(no);
printf("Factorial = %d", f);
getch();
}
int fact(int n)
{
int fc=1;
while(n > 0)
{
fc = fc * n;
n--;
}
return fc;
}
Enter the number: 4
Factorial = 24