Answer to Question #24024 in C++ for Megha

Question #24024
c++ programming for the series

1 + (1+2) + (1+2+3) + (1+2+3+4) .......................................
1
Expert's answer
2013-02-20T11:43:07-0500
#include <iostream>

int main(){

int N = 3, sum = 0, bias = 0;

for (int i = 1; i<=N; i++ ){
bias +=i;
sum += bias;
std::cout<<"i = "<<i<<"bias = "<<bias<<"\n";
}

std::cout<<"1 + (1+2) + ... + (1+2+...+"<<N<<") = "<<sum<<"\n";
getchar();

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS