Answer to Question #299781 in C++ for Nancy

Question #299781



Write a program in C++ to print the following series:






2, 5, 10, 17, 26 ………….. upto 10 terms.

1
Expert's answer
2022-02-19T11:24:13-0500
#include <iostream>
using namespace std;


int main() {
	int i=1;//take a variable
	int j=1; //take a second variable.


	for(int k=1;k<=10;k++){
		if(k!=1){
			cout<<i<<", ";//print the value.
		}
		i=i+j; //increase the value of i.
		j=j+2; //increase the value of j.
	}
	cout<<i<<"\n";
	system("pause");


	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
New on Blog