32.求1+(1+2)+(1+2+3)+(1+2+3+4)+……的前n项的和

#include<iostream>
using namespace std;
int QiuHe(int);

int main()
{
    int n;
    int sum=0;
    cout<<"please input an number : "<<endl;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        sum+=QiuHe(i);
    }
    cout<<"the mount of the series is : "<<sum<<endl;
    return 0;
}

int QiuHe(int index)
{
    int sum1=0;
    for(int j=1;j<=index;j++)
    {
        sum1+=j;
    }
    return sum1;
}

 

posted on 2014-08-07 11:37  Ji_xiaowu  阅读(358)  评论(0编辑  收藏  举报

导航