Solution:
#include <stdio.h>
int fact(int);
int main()
{ int n;
printf("Enter an integer: ");
scanf("%d",&n);
// show error if the user enters a negative integer
printf("Factorial of %d = %llu", n, fact(n));
return 0;
}
int fact(int n)
{
int i;
unsigned long long factorial = 1;
for(i=1; i<=n; ++i)
{
factorial *= i; // factorial = factorial*i;
return factorial;
}
}
0 Comments