大数阶乘
来源:互联网 发布:java date setmonth 编辑:程序博客网 时间:2024/05/21 22:37
/*
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
- 大数阶乘
- 大数阶乘。
- 大数阶乘
- ~阶乘~大数
- 大数阶乘
- 大数阶乘
- 大数阶乘
- 大数阶乘
- 大数阶乘
- 大数阶乘
- 大数阶乘
- 大数阶乘
- 大数阶乘
- 大数阶乘
- 大数阶乘!!
- 大数阶乘
- 大数阶乘
- 大数阶乘
- linux input输入子系统分析《四》:input子系统整体流程全面分析
- hdu2047
- hdu2044
- hdu2049
- POJACM3752
- 大数阶乘
- c语言中字符串处理函数
- scanf与gets函数读取字符串的区别
- 华中科技大学2010年复试上机题a+b
- 取石子游戏POJ1067
- POJ_1001 Exponentiation
- POJ_2593最大两不想交子段和问题
- C语言复杂的类型声明
- 差分进化g05测试代码