Answer to Question #262244 in C++ for kashan

Question #262244

Write a program that prompts the user to input height and width and print the hollow rectangle

as given in the output below. The program should check whether the both height and width

of rectangle are equal or not. Do not use nested loops.


1
Expert's answer
2021-11-07T01:43:08-0400


#include <iostream>


using namespace std;


int main()
{
	int height;
	int width;
	cout<<"\nEnter height of the rectangle: ";
	cin>>height;
	cout<<"\Enter width of the rectangle: ";
	cin>>width;
	for (int i = 0; i <height; i++)
	{
		for (int j = 0; j < width; j++)
		{
			if (i==0 || i==height-1 || j==0 || j==width-1)	
			    cout<<"*";		
			else
				cout<<" ";		
		}
		cout<<endl;
	}


	return 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