ĐĂNG TIN
logo
Online:
Visits:
Stories:
Profile image
Tác giả: VNNews
Trang tin cá nhân | Bài đã đăng
Lượt xem

Hiện tại:
1h trước:
24h trước:
Tổng số:
Big Factorial in C++
Monday, August 5, 2013 15:03
% of readers think this story is Fact. Add your two cents.


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;

}

Tin nổi bật trong ngày
Tin mới nhất

Register

Newsletter

Email this story

If you really want to ban this commenter, please write down the reason:

If you really want to disable all recommended stories, click on OK button. After that, you will be redirect to your options page.