hdu1042!【水题】

N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 54156    Accepted Submission(s): 15356


Problem 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
 

Author
JGShining(极光炫影)
 

Recommend
We have carefully selected several similar problems for you:   1047  1063  1316  1250  1062 
#include<stdio.h>
#include<string.h>
int a[1000000];
int main()
{
    int n, la, i, j, k;
    while(scanf("%d", &n) != EOF)
    {
        if(n == 0)
        {
            printf("1\n");
            continue;
        }
        memset(a, 0, sizeof(a));
        a[0] = 1;
        for(i = 1; i <= n; i++)
        {
            k = 0;
            for(j = 0; j < 40000; j++)
            {
                k = a[j] * i + k;
                a[j] = k % 10;
                k /= 10;
            }
        }
        for(i = 40000; i >= 0; i--)
        {
            if(a[i] != 0)
            {
                for(j = i; j>=0; j--)
                printf("%d", a[j]);
                printf("\n");
                break;
            }
        }
    }
    return 0;
}


你可能感兴趣的:(c)