61. C Program To find Factorial of a Given Number.
How does this program work?
- This Program is used to find the factorial of a given number.
Here is the code
#include <stdio.h>
int main(void)
{
int n, i;
unsigned long long factorial = 1;
printf("Enter an integer: ");
scanf("%d",&n);
// Show error if the user enters a negative integer
if (n < 0)
printf( "Error! Factorial of a negative number doesn't exist.");
else
{
for( i=1; i<=n; ++i)
{
factorial *= i;// Factorial = factorial*i;
}
printf("Factorial of %d = %llu", n, factorial);
}
return 0;
}