Answer to Question #93450 in C++ for Karan

Question #93450
Print a half pyramid with output as
1
2*2
3**3
4***4
1
Expert's answer
2019-08-28T10:08:01-0400
#include <iostream>
#include <string>


int main()
{	
	const int height = 4;


	for (int i = 1; i <= height; ++i)
	{
		for (int j = 0; j <= i; ++j)
		{
			if (j == 0 || j == i)
			{
				std::cout << std::to_string(i);
				if (i == 1) break;
			}
			else
			{
				std::cout << '*';
			}			
		}


		std::cout << std::endl;
	}
}

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