C Program to find the factorial of a given number
That means, take a number and multiply every number upto one.
In programming, take a simple for loop or while loop. Multiply and add the number from one to that number.
int i, n, fact = 1;
printf("Enter a number to find it's factorial = n");
for (i = 1; i <= n; i++)
fact = fact * i;
printf("Factorial of %d = %dn", n, fact);
C Code for factorial number:
Problem of previous code was it can’t return a large numbers factorial. That return a furbage value. So, to get a better result just use this code to find factorial in c.
int n, i;
unsigned long long factorial = 1; //take long integer to get a big factorial
printf("Enter an integer: ");
// show error if the user enters a negative integer
if (n < 0)
printf("Error! Factorial of a negative number doesn't exist.");
for(i=1; i<=n; ++i)
factorial *= i; // factorial = factorial*i;
printf("Factorial of %d = %llu", n, factorial);
C Program to find the factorial of a given number, Factorial solution, factorial demonstration, how to find a factorial, factorial c code, code factorial