Answer to Question #301375 in C++ for Kidus

Question #301375

How to can write a C++ program that will print the following shapes.


A.


*


***


*****


*******


*********


B.


*


***


*****


***


*

1
Expert's answer
2022-02-23T06:26:44-0500
#include<iostream>

using namespace std;

int main()
{
	cout<<"Shape A:\n";
	for(int i=1;i<=5;i++)
	{
		for(int j=1;j<=2*i-1;j++)
		{
			cout<<"*";
		}
		cout<<endl<<endl;
	}
	cout<<"Shape B:\n";
	for(int i=1;i<=5;i++)
	{
		
		if(i<=3)
		{
			for(int j=1;j<=2*i-1;j++)
			{
				cout<<"*";
			}
		}
		else if(i==4)
		{
			for(int j=1;j<=3;j++)
			{
				cout<<"*";
			}
		}
		else
		{
			cout<<"*";
		}
		
		cout<<endl<<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