HDU 1042(大数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042
用数组来存储结果~~~
代码:
1 #include <stdio.h> 2 #include <string.h> 3 #define N 50002 4 5 int a[N]; 6 7 void calculator(int n) 8 { 9 int i, j, c = 0; 10 a[1] = 1; 11 for(i = 1; i <= n; i++) 12 { 13 for(j = 1; j <= N; j++) 14 { 15 a[j] = a[j] * i + c; 16 c = a[j] / 10; 17 a[j] = a[j] % 10; 18 } 19 } 20 i = N; 21 while(!a[i]) 22 { 23 i--; 24 } 25 for(j = i; j >= 1; j--) 26 { 27 printf("%d", a[j]); 28 } 29 printf("\n"); 30 } 31 32 int main() 33 { 34 int n; 35 while(scanf("%d", &n) != EOF) 36 { 37 memset(a, 0, sizeof(a)); 38 calculator(n); 39 } 40 }