首页 > 编程知识 正文

大数阶乘后的零,100的阶乘

时间:2023-05-03 05:44:06 阅读:272522 作者:1644

c++ 100的阶乘 100!

源代码如下:

#include "stdafx.h"#include<iostream>using namespace std;class fun{public:fun(int nn=0){n = nn;m = 2000 * nn;p = new int[m];} ~fun(){ delete[]p; } int Getfun();private:int n;int *p;int m;};int fun::Getfun(){if (n == 0)cout << n;for (int a = 1; a < m; a++)p[a] = 0;p[0] = 1;int x = 1; //阶乘结果实际的位数for (int i = 1; i <= n; i++){for (int j = 0; j < x; j++)p[j] *= i;for (int y= 0; y<x; y++){ //进位if (p[x - 1] >= 10)x++;if (p[y] >= 10){p[y + 1] += p[y] / 10;p[y] = p[y] % 10;}}}cout << n << "!=";for (int k = x - 1; k >= 0; k--)cout << p[k];return 0;}int _tmain(int argc, _TCHAR* argv[]){fun A(100);A.Getfun();return 0;}

运行结果如下:

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。