C program to find factorial of any number – If you are searching for How to do Factorial Program in C. Today, We are going to share step by step Guide to easily find the factorial of any number through C Program . Following are all step by step Guide. The factorial of a positive integer n is equal to 1*2*3*…n. You will learn to calculate the factorial of a number using for loop in this example.
Input number: 5
Output factorial: 120
Logic to find factorial
Finding factorial is really easy you just need to know how to iterate over a loop. Finding factorial can be basically divided two steps:
- Run a loop from 1 to n (where n is the number whose factorial is to be found).
- Multiply the current loop counter value with fact (where fact is a variable that stores factorial and is initially initialized with 1).
Program to find factorial
* C program to calculate factorial of any number
int i, num;
long long fact=1;
/* Reads a number from user */
printf(“Enter any number to calculate factorial: “);
/* Runs a loop from 1 to n */
for(i=1; i<=num; i++)
fact = fact * i;
printf(“Factorial of %d = %lld”, num, fact);
So, above code is totally free of error you can easily use this for Factorial Program in C, C program to find factorial of any number find out here for all the details.