zoukankan      html  css  js  c++  java
  • 题目1076:N的阶乘

    题目描述:

     输入一个正整数N,输出N的阶乘。

    输入:

    正整数N(0<=N<=1000)

    输出:

     输入可能包括多组数据,对于每一组输入数据,输出N的阶乘

    样例输入:
    4
    5
    15
    样例输出:
    24
    120
    1307674368000
     1 #include "cstdio"
     2 #include "cstring"
     3 #include "cstdlib"
     4  
     5 int res[10010];
     6  
     7 int main()
     8 {
     9     int n;
    10     while (scanf("%d", &n) == 1)
    11     {
    12         int i, j;
    13         memset(res, 0, sizeof(res));
    14         res[0] = 1;
    15         res[1] = 1;
    16         for (i = 2; i <= n; i++)
    17         {
    18             for (j = 1; j <= res[0]; j++)
    19                 res[j] = res[j] * i;
    20              
    21             for (j = 1; j <= res[0]; j++)
    22             {
    23                 if (res[j] >= 10)
    24                 {
    25                     res[j+1] += res[j] / 10;
    26                     res[j] %= 10;
    27                     if (j == res[0])
    28                         res[0]++;
    29                 }
    30             }
    31         }
    32         for (i = res[0]; i >= 1; i--)
    33             printf("%d", res[i]);
    34         printf("
    ");
    35     }
    36     return 0;
    37 }
    
    
  • 相关阅读:
    codova 打包vue项目的坑
    vscode 开发wtl 笔记
    redis
    展开/收缩 ul
    ueditor
    xml
    NPOI
    滚动效果,有些浏览器不支持
    fileupload控件上传、文件下载
    excel函数
  • 原文地址:https://www.cnblogs.com/chchche/p/3466051.html
Copyright © 2011-2022 走看看