Any questions?
Reply Back New Topic
View Topic

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

1018 浏览:120 回复:1 赞:0 Started by Xawd 2 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 1 months ago 赞:0

厉害