Question

Write the nested loops that cause the output below to print. 1 1 2 2 3 2 3 4 2 3 1 2 1

0 0
Add a comment Improve this question Transcribed image text
Answer #1

c++ code

#include <iostream>
using namespace std;
int main()
{
  
for(int i = 1; i <= 2; ++i) //for loop for 1st and 2nd row
{
for(int j = 1; j <= i; ++j)
{
cout << j << " ";
}
cout << "\n";
}
for(int i = 3; i <= 4; ++i) //for loop for 3rd and 4nd row
{
for(int j = 2; j <= i; ++j)
{
cout << j << " ";
}
cout << "\n";
}
for(int i = 4; i <= 4; ++i) //for loop for 5th row
{
for(int j = 2; j <= i-1; ++j)
{
cout << j << " ";
}
cout << "\n";
}
for(int i = 2; i >= 1; --i) //for loop for 6th and 7th row
{
for(int j = 1; j <=i; ++j)
{
cout << j << " ";
}
cout << endl;
}
  
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write the nested loops that cause the output below to print. 1 1 2 2 3...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT