美文网首页
C++计算一个大数的阶乘的代码

C++计算一个大数的阶乘的代码

作者: we1212 | 来源:发表于2021-10-18 14:54 被阅读0次

    下边内容段是关于C++计算一个大数的阶乘的内容。

    #include <cmath>

    #include <iostream>

    using namespace std;

    int main()

    {

      unsigned int j, n, q, temp;

      int i;

      double p;

       

      while(1)

      {

        cout << "nEnter an integer to calculate factorial (0 to exit): ";

        cin >> n;

       

        if (n == 0) break;

       

        p = 0.0;

        for(j = 2; j <= n; j++)

        {

        }

        nd = (int)p + 1;

        ca = new unsigned char[nd];

        if (!ca)

        {

          cout << "Could not allocate memory!!!";

          exit(0);

        }

        for (i = 1; i < nd; i++)

        {

          ca[i] = 0;

        }

        ca[0] = 1;

       

        p = 0.0;

        for (j = 2; j <= n; j++)

        {

          for (i = 0; i <= nz; i++)

          {

            q = (temp / 10);

            ca[i] = (char)(temp % 10);

          }

        }

     

        cout << "nThe Factorial of " << n << " is: ";

        for( i = nd - 1; i >= 0; i--)

        {

          cout << (int)ca[i];

        }

        cout << endl;

       

        delete []ca;   

       

      return 0;

    }

                                   

                           

                   

                   

               

               

                   

    相关文章

      网友评论

          本文标题:C++计算一个大数的阶乘的代码

          本文链接:https://www.haomeiwen.com/subject/ikrnoltx.html