Any questions?
Reply Back New Topic
View Topic

如何累加 1018 求和数列的框架

1018 浏览:233 回复:2 赞:0 Started by Xawd 5 months ago

#include<iostream>
using namespace std;
int main()
{
    long long ans=0,n,i,s=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        s+=i;//将括号中的数进行累加  如:(1+2) 
        ans+=s; //将各个括号中数的和累加  如:(1+2)+(1+2+3)+(1+2+3+4) 
    }
    cout<<ans<<endl;
    return 0;
}
View Replies

Replied by JasonLou 4 months ago 赞:0

厉害


Replied by anna2018 2 months ago 赞:0

厉害,jasonlou