Pages

Thursday 10 December 2015

Area and perimeter of a rectangle using C++



Rectangle: It is a quadrilateral which has four right (90 degree) angle triangle.

Area of the rectangle:    $height \times width$
Perimeter of the rectangle :  $ 2 \times (height + width) $

Algorithm: 

  1. Start
  2. Enter the height and width of the rectangle
  3. Area = $height \times width$
  4. Circumference =  $ 2 \times (height + width) $
  5. Stop




#include "iostream"

using namespace std;

int main()

{

    int width,height,area,perimeter;

    cout<<"Enter  width of rectangle : ";

    cin >> width;

    cout<< "Enter height of rectangle : ";

    cin >> height;

    area = height * width;
    cout<<"Area of rectangle : "<<area<<endl;

    perimeter=2*(height+width);

    cout<< "Perimeter of rectangle : "<<perimeter<<endl;

return (0);

}


INPUT :       Enter the width of rectangle: 12
                     Enter the height of rectangle: 10
OUTPUT :  Area of the rectangle: 120
                    Perimeter of the rectangle: 44


No comments:

Post a Comment