首页 > 代码库 > 33.求1*2+2*3+3*4+……前n项的和

33.求1*2+2*3+3*4+……前n项的和

#include<iostream>using namespace std;int XiangCheng(int );int main(){    int n,sum=0;    cout<<"please input an number : "<<endl;    cin>>n;    for(int i=1;i<=n;i++)    {        sum+=XiangCheng(i);    }    cout<<"the answer is : "<<sum<<endl;    return 0;}int XiangCheng(int index){    int m;    m=index*(index+1);    return m;}