C program to find factorial of number - Explanation - Download
In this post, we are going to discuss, factorial of a number in the simplest way.
We are also adding a c program and its explanation.
Now ,what is a factorial.
Factorial of a number,is the product of all natural numbers upto that number.
That is, factorial of a number say 5 is given by,
Factorial of 0 is defined as one.
Have a look at the flowchart of the program.Based on this we are program.
After starting program,we will ask the user to input number,say n.
Then we will check whether the number is a whole number.
Since factorial is not defined for negative numbers.Now the logic of the program enters.
We are considering the series of multiplications in a loop.
I is the loop variable.We are incrementing the value of I after every multiplication.
The working is like that.First we will check if I is less than n.
If yes we will multiple it with fact.this process continues till the condition fails.
Now we have factorial in fact,display it.This is the basic logic of program.
If you find any difficulty,check this example.
I is incremented.i=2 now.
Fact changes to 1*2.
I is incremented and equals to 3.
Fact changes to 2*3=6.
printf("\n Enter the number : ");
printf("Factorial of %d = %d",n,fact);