#include<iostream>
using namespace std;
void main()
{
int A(int n);//递归求阶乘
cout << "请输入N值:";
int i, N, sum = 0;
cin >> N;
if (N > 0)
{
for (i = N; i >= 1; i--)
{
sum += A(i);
}
cout << "结果:" << sum << endl;
}
else
cout << "N必须为正整数!\n";
system("pause");
}
int A(int n)
{
if (n > 1)
return A(n - 1)*n;
if (n == 1)
return 1;
}
Last modification:December 5th, 2018 at 07:40 pm
© 允许规范转载