Answer to Question #348170 in C++ for Smacker

Question #348170

Write a c++ code for the output using loop



1



2 3



4 5 1



2 3 4 5



1 2 3 4 5

1
Expert's answer
2022-06-06T08:57:33-0400
#include <iostream>


using namespace std;


int main()
{
	int k = 0;
	int t=1;
	for (int i = 0; i < 3; i++)
	{
		for (int j = 1; j <=5 ; j++)
		{
			cout << j << " ";
			if (++k == t)
			{
				cout << endl;
				t++;
				k=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
APPROVED BY CLIENTS