zoukankan      html  css  js  c++  java
  • 大数相乘nyoj28

    描述我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?

     
    输入
    输入一个整数m(0<m<=5000)
    输出
    输出m的阶乘,并在输出结束之后输入一个换行符
    样例输入
    50
    样例输出
    30414093201713378043612608166064768844377641568960512000000000000
     1  
     2 #include <stdio.h>
     3 #include <string.h>
     4 #define M 20000
     5 int shu[M];
     6 
     7 int main()
     8 {
     9     int m, i, n, b, t, e;
    10     while(scanf("%d", &m) != EOF){
    11 
    12         memset(shu, 0, sizeof(shu));
    13         shu[0] = 1;
    14         n = 0;/*n表示存放进位*/
    15         for(i = 1; i <= m; i++)
    16         {        
    17             t = 0;/*t表示进位的数值*/
    18             e = 0;//记得初始化
    19             for(b = 0; b <= n; b++)
    20             {
    21             //    shu[b] *= i;
    22             //    shu[b+1] = shu[b] / 10;
    23             //    shu[b] %= 10;
    24                 e = shu[b] * i + t;
    25                 t = e / 10;
    26                 shu[b] = e % 10;
    27                 if(b == n && t != 0)/*为什么要有个b == n?因为有时不是在最高位进1,会产生多余的n++影响输出结果*/
    28                     n++;
    29             }
    30 
    31         }
    32         for(i = n; i >= 0; i--){
    33 
    34             printf("%d", shu[i]);
    35 
    36         }    
    37         putchar('
    ');
    38     
    39     }
    40     return 0;
    41 }        
    View Code


    把第二个数分别与第一个数的个位、十位等相乘

  • 相关阅读:
    cookie,sessionStorage,localStorage
    存储方式与传输方式
    为什么css放在顶部而js写在后面
    常见的web安全及防护原理
    web缓存
    http协议理解
    http与https
    get/post的区别
    JZOJ 3571. 【GDKOI2014】内存分配
    JZOJ 3570. 【GDKOI2014】壕壕的寒假作业
  • 原文地址:https://www.cnblogs.com/the-one/p/3269065.html
Copyright © 2011-2022 走看看