/*
Description:大数阶乘 n!
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_SIZE 100024
int ans[MAX_SIZE+10];
void Multiply(int n)
{
int i, move = 0;
for(i = 0; i < MAX_SIZE; ++i){
ans[i] = ans[i]*n + move;
if(ans[i] >= 10){
move = ans[i]/10;
ans[i] %= 10;
//printf("move = %d\n", move);
}
else move = 0;
}
}
void Print(int a[])
{
int isPrint = 0;
int i;
for(i = MAX_SIZE; i >= 0; --i)
if(isPrint){
printf("%d", a[i]);
}
else if(a[i]){
printf("%d", a[i]);
isPrint = 1;
}
printf("\n");
}
int main()
{
int i, n;
//freopen("t1.txt", "r", stdin);
// freopen("ttt1.txt", "w", stdout);
while(scanf("%d", &n) != EOF){
memset(ans, 0, sizeof(ans));
ans[0] = 1;
for(i = 2; i <= n; ++i)
Multiply(i);
Print(ans);
}
system("pause");
return 0;
}
本文出自 “东方快翔” 博客,请务必保留此出处http://hustluy.blog.51cto.com/1792080/608840