C++ program to find factorial of 100 or very large numbers Given by User in C++
Code:
#include
using namespace std;
#define MAX 10000
int length = 0;
int fact[MAX];
void factorial(int num);
void multiply(int num);
int main()
{
int num;
cout
cin>>num;
fact[0] = 1;
factorial(num);
cout
for (int i = length; i >= 0 ; i–)
cout
cout
system(“pause”);
return 0;
}
void factorial(int num)
{
for (int i = 2; i
multiply(i);
}
void multiply(int num)
{
long i, r = 0;
int arr[MAX];
for (i = 0; i
arr[i] = fact[i];
for (i = 0; i
{
fact[i] = (arr[i] * num + r) % 10;
r = (arr[i] * num + r) / 10;
}
if (r != 0)
{
while (r != 0)
{
fact[i] = r % 10;
r = r / 10;
i++;
}
}
length = i – 1;
}
2013-08-05 14:00:04
Nguồn: http://nguyenhaiblog.wordpress.com/2012/08/22/big-factorial-in-c/