• HDU 1042 N!(大数阶乘)


                      N!



     

    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
     
    代码:
     1 #include<cstdio>
     2 using namespace std;
     3 
     4 int main()
     5 {
     6     int i,n,digit,temp,carry,j;
     7     int a[40005];
     8     while(scanf("%d",&n)!=EOF)
     9     {
    10         a[0]=1;
    11         digit=0;
    12         for(i=2;i<=n;i++)
    13         {
    14             for(carry=0,j=0;j<=digit;j++)
    15             {
    16                 temp=a[j]*i+carry;
    17                 a[j]=temp%10;
    18                 carry=temp/10;
    19             }
    20             while(carry)
    21             {
    22                 a[++digit]=carry%10;
    23                 carry/=10;
    24             }
    25         }
    26         for(i=digit;i>=0;i--)
    27         printf("%d",a[i]);
    28         printf("
    ");
    29     }
    30     return 0;
    31 } 
  • 相关阅读:
    DAY9 函数初识(各种参数的用法)
    CSS背景
    HTML/CSS 练习
    从JDBC到commons-DBUtils
    SQL
    MYSQL数据库基本操作
    JDBC
    Stream数据流(Collection接口扩充)
    Stack栈
    Map集合接口
  • 原文地址:https://www.cnblogs.com/homura/p/4674235.html
Copyright © 2020-2023  润新知