Write a program in C++ to print the following series:
2, 5, 10, 17, 26 ………….. upto 10 terms.
#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;
}
Comments
Leave a comment