A Platform to LEARN | CODE | ACHIEVE

Connect :

#### TO GENERATE THE FACTORIAL OF A NUMBER IN C

Code

```#include<stdio.h>
int main()
{
int n;
int i;
int fact=1;
printf("ENTER THE NUMBER :");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("THE FACTORIAL OF %d IS : %d",n,fact);
return 0;
}
```

Output

ENTER THE NUMBER :10
THE FACTORIAL OF 10 IS : 3628800

What we did - Our Approach

In this problem we have to generate the factorial of a number.

Let us consider an example :
Suppose we have to find the factorial of 6,hence this means that we have to calculate 1*2*3*4*5*6. It is clear that we can find the factorial of any number 'n',by multiplying each number from i:1 to 'n',such that fact=fact*i .This can be achieved by using for loop from 1 to 'n'. Note : It is mandatory for you to initialize the result variable(here fact) with 1 as in an equation ' fact=fact*i ' , if fact=0 then overall result will be 0 as well.

See this code in :

C++

Java

Participate in our MONTHLY CHALLENGE,and get a chance to get listed on our site and win the TITLE of "MR.GEEK".

RUSH TO OUR MONTHLY CHALLENGE

#### A Platform to LEARN | CODE | ACHIEVE

Connect :

SHARE:

For any Queries,suggestions,feel free to Mail us at :
codeofgeeks@gmail.com

For reporting any kind of copyright voilation,mail us at : cogcopyclaim@gmail.com 