C++编程程序设计题目求1!+2!+3!+4!+...+n!的结果,阶乘之和

2024-11-01 14:24:51
推荐回答(1个)
回答1:

#include
using namespace std;
int mul(int n)
{
int m = 1;
while(n != 0)
{
m = m*n;
n--;
}
return m;
}
int main()
{
int i = 1,n;
int sum = 0;
cout<<"请输入n:";
cin>>n;
do{
sum = sum + mul(i);
i++;
}while(i<=n);
cout<<"sum = "< system("pause");
return 0;
}