/* C program to find factorial of a given number. Factorial of number n is defined as follow:
n! = 1 * 2 * 3 * 4 * ....* n
*/#include<stdio.h>
int main()
{
int i, n;
double fact=1;
printf("Enter number (n): ");
scanf("%d",&n);
if (n < 0)
printf("Factorial is not possible for negative number.");
else
{
for(i=1; i<=n; i++)
{
fact = fact * i;
}
printf("Factorial of number %d = %f", n, fact);
}
}
* * * * *
Output of program:
Enter number (n): 5
Factorial of number 5 = 120.000000
No comments:
Post a Comment