作者在 2008-11-22 20:55:09 发布以下内容
计算阶乘,用数组存放
#include <iostream>
using namespace std;
const int size = 100;
int J[size];
using namespace std;
const int size = 100;
int J[size];
void jiecheng(const int number)
{
/////////1 对J[]初始化////////
for(int i = 0; i < size; i++)
{
J[i] = 0;
}
J[size - 1] = 1;
if(number == 0)
{
J[size - 1] = 0;
return;
}
////////1/////////
{
/////////1 对J[]初始化////////
for(int i = 0; i < size; i++)
{
J[i] = 0;
}
J[size - 1] = 1;
if(number == 0)
{
J[size - 1] = 0;
return;
}
////////1/////////
int jinwei = 0;
for(i = 2; i <= number; i++)
{
int position = size - 1;
/////////2///////
int flag = 1;
for(int j = 0; j < size; j++)
{
if(flag)
{
J[position] *= i;
}
flag = 1;
if(J[position] >= 10)
{
jinwei = J[position] / 10;
J[position] %= 10;
J[position - 1] *= i;
J[position - 1] += jinwei;
flag = 0;
}
position--;
}
////////2////////
}
}
}
//用主程序来测测好不好使:
int main()
{
jiecheng(8);
for(int i = 0; i < size; i++)
{
cout << i << " : " << J[i] << endl;
}
return 0;
}
int main()
{
jiecheng(8);
for(int i = 0; i < size; i++)
{
cout << i << " : " << J[i] << endl;
}
return 0;
}