Program To Find Area and Perimeter of Rectangle in C++
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++ :
using namespace std;
cout<<"**CALACULATE AREA AND PERIMETER**";
cout<<endl<<"ENTER WIDTH OF RECTANGLE = ";
cout<<"ENTER HEIGHT OF RECTANGLE = ";
cout<<endl<<"AREA OF RECTANGLE: "<<area<<endl;
cout<<"PERIMETER OF RECTANGLE: "<<perimeter<<endl;
First of all, we declared four integer type variables named h, w, area & perimeter.
Height is denoted by h and Width is denoted by w.
After getting input from user, we used following formulas to calculate area and perimeter of rectangle.
After calculating the values, we printed them on screen using cout statement.
Recommended reading: How to Add Two Numbers in C++
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.