# Write a simple program for finding factorial in C++ ?

#### Sainath Rao

• Dec 6th, 2011

```Codeint calfactorial (int x)
{
int finalx = 1;
if (x==1) return 1;
for (int i = 1; i <= x; ++i) finalx = finalx * i;
return finalx;
}```

#### Paul_Singh Profile Answers by Paul_Singh

• Feb 7th, 2012

Should use the fact that in n!, n is only a positive integer. As the number increase fairly rapidly, maybe a double return is better than a signed int.

```Codedouble factorial( unsigned int n )
{
double result = 1;
for(unsigned int i = 1; i <=n; i++ )
{
result*=i;
}
return result;
}```

#### FHGCVJ

• Apr 14th, 2012

..

```Codeint calfactorial (int x)
{
int finalx = 1;
if (x==1||x==0) return 1;
for (int i = 1; i <= x; ++i) finalx = finalx * i;
return finalx;
}```

#### Anugya Singh

• Sep 4th, 2012

```Code#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,i,f=1;
cout<<"Enter the Number whose factorial value is to be find
";
cin>>a;
for(i=a;i>0;i--)
{
f=f*i;
}
cout<<"Fctorial is "<<f;
getch();
}```

#### sakshi

• Oct 4th, 2012

```Codeclass factorial
{
public static void main(String args[])
int f=1,i,n;
for(i=1;i<=n;i++)
{
f=f*i;
}
Console.WriteLine("factorial of the no :"+f);

}```  