zoukankan      html  css  js  c++  java
  • N!

    N的阶乘

    Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

    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 7300

    #define INF 100000 // 5

    int num[N];

    void jiecheng(int n);
    void put(int n);

    int main()
    {
        int n;

        while(scanf("%d", &n) != EOF)
        {
            jiecheng(n);
            put(n);
        }
        return 0;
    }

    void jiecheng(int n)
    {
        int i, j;
        memset(num, 0, sizeof(num));

        num[0] = 1;   //只把第一位赋值了

        for(i = 1; i <= n; i++)
        {
            for(j = 0; j < 7300; j++)
            {
                num[j] *= i;  //只有第一位乘进去了
            }

            for(j = 0; j < 7300; j++)  //这个for循环要在里边,防止每次的乘的结果超过5位?
            {
                num[j+1] += num[j] / INF; 
                num[j] %= INF;                  //大数处理都一样。。
            }
        }
    }
    void put(int n)    //大数输出都一样
    {
        int i;

        for(i = 7300; i >= 0; i--)
        {
            if(num[i])
                break;
        }

        printf("%d", num[i]);

        for(i--; i >= 0; i--)
            printf("%05d", num[i]);   //每次5位,不足前导0
        printf(" ");
    }

    让未来到来 让过去过去
  • 相关阅读:
    eval()
    promise
    console.log()和console.dir()、console.table()的区别
    SSM框架搭建+easyui增删改查
    虚成员
    关键字 explicit
    复制控制
    变量、静态变量
    关键字 extern
    关键字 static
  • 原文地址:https://www.cnblogs.com/Tinamei/p/4461261.html
Copyright © 2011-2022 走看看