Object
Write a program to draw rectangles of given width and length representing different rooms in a house.
Algorithm
- Declare a function void rectangle(int, int), which accepts two integer arguments but returns no value.
The Function main - Write Drawing room.
- Call function rectangle(6,3).
(6 and 3 are length and width of the room) - Write Bedroom.
- Call function rectangle(8,2).
- Write Bathroom.
- Call function rectangle(2,1).
- Write Kitchen.
- Call function rectangle(4,3).
- Exit.
Defining the Function void rectangle(int length, int width) - Declare integer variables j and k.
- Repeat FOR j = 1 to j <= width
- Repeat FOR k = 1 to k <= length
- Write \xDB.
(where \xDB is the code for one rectangle)
- [End of inner FOR loop.]
- Write new line.
- [End of outer FOR loop.]
- Write \xDB.
- Exit.
Flowchart

C++ Source Code
// program 80
#include<iostream>
using namespace std;
void rectangle(int length, int width);
int main()
{
cout << "\nDrawing room\n";
rectangle(6, 3);
cout << "\nBedroom\n";
rectangle(8, 2);
cout << "\nBathroom\n";
rectangle(2, 1);
cout << "\nKitchen\n";
rectangle(4, 3);
return 0;
}
void rectangle(int length, int width)
{
for (int j = 1; j <= width; j++)
{
for (int k = 1; k <= length; k++)
cout << "\xDB";
cout << endl;
}
}
C Source Code
/*program 80*/
#include<stdio.h>
void rectangle(int length, int width);
int main()
{
printf("\nDrawing room\n");
rectangle(6,3);
printf("\nBedroom\n");
rectangle(8,2);
printf("\nBathroom\n");
rectangle(2,1);
printf("\nKitchen\n");
rectangle(4,3);
return 0;
}
void rectangle(int length, int width)
{
int j,k;
for(j=1; j<=width; j++)
{
for(k=1; k<=length; k++)
printf("\xDB");
printf("\n");
}
}
Output

