求1+2!+3!+...+20!的和
#include<iostream.h>void main()
{
int i=2;
long int b,a;
while(i<21)
{
b=i;
a=1;
while(b!=0)
{
b*=--b;
}
a+=b;
i++;
}
cout<<a<<endl;
}
麻烦各位大虾了,这个帮忙修改下啊
#include <iostream> using std::cout; using std::endl; using std::cin; double Factorial(int); int main() { int num = 20; double result = 1; for (int i = 1; i <= num; i++) { result += Factorial(i); } cout << result<<endl; cin.get(); return 0; } double Factorial(int number) { double result = 1; if (number > 0) { for (int i = 1; i <= number; i++) { result *= i; } } return result; }