// test13.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
class Solution {
public:
int Sum_Solution(int n) {
if (n == 1)
return 1;
else
return Sum_Solution(n - 1) + n;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Solution so;
int num;
while (cin>>num)
{
cout << "1+2+...+" <<num <<"的和是: "<< so.Sum_Solution(num) << endl;
}
}
注意:f(n)=f(n-1)+n