Answer to Question #342889 in C++ for Padi

Question #342889

(iii) Write a function void rectangle(int w, int h) to print an open rectangle of asterisks (*). The parameters w and h are the width and the height of the rectangle, expressed in number of asterisks


1
Expert's answer
2022-05-25T10:23:29-0400
#include <iostream>
using namespace std;
 
 void rectangle(int w, int h) {
    int i, j;
    
    for(i=0;i<h;i++) {
        for(j=0;j<w;j++) {
            cout<< "*" <<' ';
        }
        cout<<endl;
      }
  }
 
int main() {
    int width, height;
      
   cout<<"Enter width: ";
   cin>>width;
   
   cout<<"Enter height: ";
   cin>>height;
   
   rectangle(width, height);
 
    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