Answer to Question #4460 in C++ for sanando chakraborty

Question #4460
write a program to print 1,2,-3,4,5,-6,....,nth term.
1
Expert's answer
2011-10-11T08:31:34-0400
#include <iostream>

using namespace std;

void
main(void){
int n = 0;
cout << "Please, enter n = ";

cin >> n;
for(int i = 0; i <= n; ++i)
{
& if ((i
% 3) == 0)
& cout << -i;
& else
& cout
<< i;
& cout << ",";
}
cout << "\nInput
0 and press Enter exit...";
cin >> n;
}

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