C++ Program To Find Area And Perimeter Of Rectangle

Last Updated : 13 Aug, 2026

A rectangle is a four-sided plane figure with four right angles, where opposite sides are equal in length. Its area measures the surface enclosed by the rectangle, while its perimeter represents the total length of its boundary.

  • The area depends on the product of the rectangle's length and width.
  • The perimeter is twice the sum of its length and width.

Illustration

Input: Length = 4, Width = 5
Output: Area = 20
Perimeter = 18

Input: Length = 2, Width = 3
Output: Area = 6
Perimeter = 10

Formula

The area and perimeter of a rectangle are calculated using:

\text{Area} = \text{Length} \times \text{Width}

\text{Perimeter} = 2 \times (\text{Length} + \text{Width})

Approach

  • Initialize the length and width of the rectangle.
  • Calculate the area by multiplying the length and width.
  • Calculate the perimeter using twice the sum of the length and width.
  • Print the calculated area and perimeter.

Example: Program to find the area and perimeter of a rectangle.

C++
#include<iostream>
using namespace std;

// Utility function
int areaRectangle(int a, int b)
{
   int area = a * b;
   return area;
}

int perimeterRectangle(int a, int b)
{
   int perimeter = 2*(a + b);
   return perimeter;
}

// Driver code
int main()
{
  int a = 5;
  int b = 6;
  cout << "Area = " << 
           areaRectangle(a, b) << 
           endl;
  cout << "Perimeter = " << 
           perimeterRectangle(a, b);
  return 0;
} 

Output
Area = 30
Perimeter = 22

Explanation: The program initializes the length and width as 5 and 6. It calculates the area using length × width and the perimeter using 2 × (length + width), then displays both results.

Comment