用while循环进行求解,代码如下:
int ContinuousMultiplication(int num)
{
int tmp = 1;
while (num)
{
tmp= tmp*num;
num--;
}
return tmp;
}
int main()
{
int i = 0,allnum=0;
for (i = 1; i <= 20; i++)
{
allnum +=ContinuousMultiplication(i);
}
cout << allnum << endl;
system("pause");
return 0;
}
时间: 2024-12-28 19:42:04