B - 2
Time Limit:5000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 1042
Description
Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
Input
One N in one line, process to the end of file.
Output
For each N, output N! in one line.
Sample Input
1 2 3
Sample Output
1 2 6 代码:
#include<stdio.h>
#include<string.h>
#define N 11000
void pp(int a[],int num)
{
int i;
for(i = 0;i < N;i++)
a[i] = a[i] * num;
for(i = 0;i < N;i++)
{
a[i+1] += a[i] / 10000;
a[i] = a[i] % 10000;
}
}
void put(int a[])
{
int i=N-1;
while(!a[i])
i--;
printf("%d",a[i]);
for(i--;i>=0;i--)
printf("%04d",a[i]);
}
int main()
{
int a[N];
int n,i;
while(scanf("%d",&n) != EOF)
{
memset(a,0,sizeof(a));
a[0]=1;
for(i=1;i<=n;i++)
{
pp(a,i);
}
put(a);
printf("\n");
}
return 0;
}