(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
#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;
}
Comments
Leave a comment