Program To Find Area and Perimeter of Rectangle in C++

SHARE THIS ARTICLE |

This program is made to find area and perimeter of rectangle in C++.

Area and Perimeter of Rectangle:

A rectangle is a four sided figure with two pairs of parallel lines. Each set of parallel lines has the same length. Area of rectangle is the number of square units inside the rectangle. Area of rectangle is measured by multiplying width and height. So the formula would be:

AREA = WIDTH * HEIGHT

The perimeter of a rectangle is the distance around the outside of the rectangle. The formula for perimeter is:

PERIMETER = 2 * (WIDTH + HEIGHT)

 Recommended reading: Finding Factorial of A Number in C++

Code To Find Area and Perimeter of Rectangle in C++ :

#include<iostream>
using namespace std;
int main()
 {
    int w,h,area,perimeter;
    cout<<"**CALACULATE AREA AND PERIMETER**";
    cout<<"\nENTER WIDTH OF RECTANGLE = ";
    cin>>w;
    cout<<"ENTER HEIGHT OF RECTANGLE = ";
    cin>>h;
    area=h*w;
    cout<<"\nAREA OF RECTANGLE: "<<area<<endl;
    perimeter=2*(h+w);
    cout<<"PERIMETER OF RECTANGLE: "<<perimeter<<endl;
    return 0;
 }

Code Explanation:

First of all, we declared four integer type variables named hwarea perimeter.

Height is denoted by and Width is denoted by w.

After getting input from user, we used following formulas to calculate area and perimeter of rectangle.

area=h*w;
perimeter=2*(h+w);

After calculating the values, we printed them on screen using cout statement.

 Recommended reading: How to Add Two Numbers in C++

Output:

Program To Find Area and Perimeter of Rectangle in C++

If you liked this article, then I would really appreciate if you follow us on Twitter and Facebook.

If you have any question then you can ask me in comments. I would like to answer them.

You can also Click Here to Download Exercise Files.