Member-only story
C Program To Find Factorial of a Number with Example
In this tutorial, you will learn to write a C program to find factorial of a number in the C language for example. I will explain the step-by-step process to find the factorial of any given number.
Also read, For Loop Statement in C With Example
Logic to write C program to find factorial of a number
Step 1:- Initially, we will declare three integer numbers as shown below
whereas ‘i’ is used as the increment when the for loop executes
’n’ is considered as the number for which factorial is defined
‘fact’ is the variable used to store the result of the factorial.
Step 2:- Next, we will run a for loop up to the given factorial number. Suppose, we run a for loop from ‘1’ to ‘5’ for the number 5 as shown below
Step 3:- Now, we will declare an integer variable ‘fact’ and assign the value 1 as shown below
Step 4:- Now, each incremented value of the for loop will be multiplied by the above fact variable, and also the result will be stored in the ‘fact’ variable one by one as shown below
For '1', the value of the fact variable will be fact = fact*1 i.e. fact = 1*1 and it becomes face = 1;