Episode 15: Factorial

Share this content:

Factorial in C Programming

Do you know about Factorial? let’s say factorial of 5 then it will be 5*4*3*2*1 = 120.

So you have to get a number from user let say n; fact=1

Apply in a loop i=n; i>0;i–

fact=fact*i;

that means first 5=1*5; in second iteration: 20=5*4; third iteration: 60=20*3…. it will go on till i >0 (i = 1)

 

Code:

 

Output:

Enter the number:5

The factorial of number is : 120

Share this content:

Leave a Reply

Your email address will not be published. Required fields are marked *

TechGenBlog © 2017 | With ❤ From India