Object

Write a program to draw rectangles of given width and length representing different rooms in a house.

Algorithm

  1. Declare a function void rectangle(int, int), which accepts two integer arguments but returns no value.
    The Function main
  2. Write Drawing room.
  3. Call function rectangle(6,3).
    (6 and 3 are length and width of the room)
  4. Write Bedroom.
  5. Call function rectangle(8,2).
  6. Write Bathroom.
  7. Call function rectangle(2,1).
  8. Write Kitchen.
  9. Call function rectangle(4,3).
  10. Exit.
    Defining the Function void rectangle(int length, int width)
  11. Declare integer variables j and k.
  12. Repeat FOR j = 1 to j <= width
  13. 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.]
  14. 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

Design a site like this with WordPress.com
Get started