In this example, you will learn a c++ program to find the area and perimeter of a rectangle.
The area is calculated by the length times the width. If we have length =8 and width=5 the area will become 8X5 = 40.
While on the other side the perimeter is the path that surrounds the rectangle and is calculated by 2X (length + width). 2X (8 + 5)=26
Example: C++ program to find the area and perimeter of a rectangle
This program takes length and width from the user and displays its area and perimeter on the screen.
//C++ program to find area and perimeter of rectangles
#include <iostream>
using namespace std;
int main()
{
int area, perimeter, width, length;
cout<<"Input total length of the rectangle: ";
cin>>length;
cout<<"Input total width of the rectangle: ";
cin>>width;
area=(length*width);
perimeter=2*(length+width);
cout<<"\n"<<"The area of the rectangle will be: "<< area << endl;
cout<<"The perimeter of the rectangle will be: "<< perimeter << endl;
return 0;
}