zoukankan      html  css  js  c++  java
  • 九度OJ 1067 n的阶乘 (模拟)

    题目1067:n的阶乘

    时间限制:1 秒

    内存限制:32 兆

    特殊判题:

    提交:5666

    解决:2141

    题目描写叙述:

    输入一个整数n,输出n的阶乘

    输入:

    一个整数n(1<=n<=20)

    输出:
    n的阶乘
    例子输入:
    3
    例子输出:
    6
    #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
    ",a[n]);
            else
            {
                int i=2;
                while(a[i])i++;
                for(;i<=n;++i)
                {
                    a[i]=a[i-1]*i;
                }
                printf("%lu
    ",a[n]);
            }
        }
        return 0;
    }
     
    /**************************************************************
        Problem: 1067
        User: kirchhoff
        Language: C
        Result: Accepted
        Time:0 ms
        Memory:912 kb
    ****************************************************************/



  • 相关阅读:
    Lua 的元表怎么理解
    Lua中的元表与元方法
    Lua 的元表怎么理解
    VMware Workstation 系统备份-虚拟机克隆方法
    Lua中的元表与元方法
    bzoj2809
    bzoj2733
    bzoj1334
    bzoj1211
    bzoj3083 3306
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/7400079.html
Copyright © 2011-2022 走看看