Question: #include using namespace std; typedef long long ll; int main() { ll n,i,s=0,s1=0; cout < >n; for(i=1;i

#include using namespace std; typedef long long ll; int main() { ll n,i,s=0,s1=0;

cout<<"enter n:"; cin>>n;

for(i=1;i<=n;i++) s+=i*(n-i+1);

s1=(n*(n+1)*(n+2))/6;

cout<<"using formula sum is:"<

cout<<"Without formula using loop sum is:"<

Could you please help me to understand the for loop(bold part) which gives same result as s1. if possible could please explain it step by step (for example what is i and what is the mening of s+=i*(n-i+1)? Also, could you please answer questions in clear hand-writing and show me the full process, thank you (Sometimes I get the answer which was difficult to read).Thanks a lot.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!