#include <stdio.h>
int factorial(int n);
int main()
{
int fact;
printf("Please enter a number:");
scanf("%d", &fact);
printf("The factorial of %d is:%d",fact, factorial(fact));
return 0;
}
int factorial(int n)
{
int i;
int factorial = 1;
for (i = 1; i<= n; i++)
factorial = factorial * i;
return factorial;
}
No comments:
Post a Comment