下边内容段是关于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;
}
网友评论