九度OJ 1067 n的阶乘 (模拟)
#include<stdio.h>
unsigned long int a[21];
void init(){
    a[0]=a[1]=1;
}
int main(int argc, char *argv[])
{
    int n;
    init();
    while(~scanf("%d",&n))
    {
        if(a[n])
            printf("%lu\n",a[n]);
        else
        {
            int i=2;
            while(a[i])i++;
            for(;i<=n;++i)
            {
                a[i]=a[i-1]*i;
            }
            printf("%lu\n",a[n]);
        }
    }
    return 0;
}
 
/**************************************************************
    Problem: 1067
    User: kirchhoff
    Language: C
    Result: Accepted
    Time:0 ms
    Memory:912 kb
****************************************************************/
                    
                
                
            
        
浙公网安备 33010602011771号