The Wayback Machine - https://web.archive.org/web/20240622223507/https://www.geeksforgeeks.org/program-area-perimeter-rectangle/
Open In App

Program for Area And Perimeter Of Rectangle

Last Updated : 16 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

A rectangle is a flat figure in a plane. It has four sides and four equal angles of 90 degree each. In rectangle all four sides are not of equal length like square, sides opposite to each other have equal length. Both diagonals of the rectangle have equal length.

Examples:  

Input : 4 5
Output : Area = 20
         Perimeter = 18

Input : 2 3
Output : Area = 6
         Perimeter = 10

Formulae :  

Area of rectangle : a*b 
Perimeter of rectangle: 2*(a + b) 

C++




// CPP program to find area
// and perimeter of rectangle
#include<bits/stdc++.h>
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 program
int main()
{
  int a = 5;
  int b = 6;
  cout << "Area = " << areaRectangle(a, b) << endl;
  cout << "Perimeter = " << perimeterRectangle(a, b);
  return 0;
} 


Java




// Java program to find area
// and perimeter of rectangle
import java.io.*;
  
class Geometry {
  
    // Utility function
    static int areaRectangle(int a, int b)
    {
       int area = a * b;
       return area;
    }
  
    static int perimeterRectangle(int a, int b)
    {
       int perimeter = 2*(a + b);
       return perimeter;
    }
      
    // Driver Function
    public static void main (String[] args) {
  
        int a = 5;
        int b = 6;
        System.out.println("Area = "+ areaRectangle(a, b));
        System.out.println("Perimeter = "+ perimeterRectangle(a, b));
  
    }
}
  
// This code is contributed by Chinmoy Lenka


Python3




# Python3 code to find area
# and perimeter of rectangle
  
# Utility function
def areaRectangle(a, b):
    return (a * b)
  
def perimeterRectangle(a, b):
    return (2 * (a + b))
  
# Driver function
a = 5;
b = 6;
print ("Area = ", areaRectangle(a, b))
print ("Perimeter = ", perimeterRectangle(a, b))
  
# This code is contributed by 'saloni1297'.


C#




// C# program to find area
// and perimeter of rectangle
using System;
  
class GFG {
  
    // Utility function
    static int areaRectangle(int a, int b)
    {
        int area = a * b;
        return area;
    }
  
    static int perimeterRectangle(int a, int b)
    {
        int perimeter = 2 * (a + b);
        return perimeter;
    }
  
    // Driver Function
    public static void Main()
    {
  
        int a = 5;
        int b = 6;
          
        Console.WriteLine("Area = "
                      + areaRectangle(a, b));
        Console.WriteLine("Perimeter = " 
                 + perimeterRectangle(a, b));
    }
}
  
// This code is contributed by vt_m.


PHP




<?php
// PHP program to find area
// and perimeter of rectangle
  
// Utility function
function areaRectangle( $a, $b)
{
    $area = $a * $b;
    return $area;
}
  
function perimeterRectangle( $a, $b)
{
    $perimeter = 2 * ($a + $b);
    return $perimeter;
}
  
// Driver program
$a = 5;
$b = 6;
echo("Area = " );
echo(areaRectangle($a, $b));
echo("\n");
echo( "Perimeter = ");
echo(perimeterRectangle($a, $b));
  
// This code is contributed by vt_m.
?>


Javascript




<script>
  
// Javascript program to find area 
// and perimeter of rectangle 
  
// Utility function 
function areaRectangle(a, b) 
{ 
    let area = a * b; 
    return area; 
} 
  
function perimeterRectangle(a, b) 
{ 
    let perimeter = 2*(a + b); 
    return perimeter; 
} 
  
// Driver program 
   
let a = 5; 
let b = 6; 
document.write("Area = " + areaRectangle(a, b) + "<br>"); 
document.write("Perimeter = " + perimeterRectangle(a, b)); 
   
// This code is contributed by Manoj
  
</script>


Output : 

Area = 30
Perimeter = 22

Time complexity : O(1) 
Auxiliary Space : O(1)

 



Similar Reads

JavaScript program to find Area and Perimeter of Rectangle
A rectangle is a flat figure in a plane. It has four sides and four equal angles of 90 degrees each. In a rectangle all four sides are not of equal length like a square, sides opposite to each other have equal length. Both diagonals of the rectangle have equal lengths. Examples: Input: 4 5 Output: Area = 20 Perimeter = 18 Input: 2 3 Output: Area =
1 min read
Maximum area of rectangle possible with given perimeter
Given the perimeter of a rectangle, the task is to find the maximum area of a rectangle which can use n-unit length as its perimeter. Note: Length and Breadth must be an integral value. Example: Input: perimeter = 15 Output: Maximum Area = 12 Input: perimeter = 16 Output: Maximum Area = 16 Approach: For area to be maximum of any rectangle the diffe
3 min read
Ratio of area of a rectangle with the rectangle inscribed in it
Given two rectangles, X with a ratio of length to width a:b and Y with a ratio of length to width c:d respectively. Both the rectangles can be resized as long as the ratio of sides remains the same. The task is to place the second rectangle inside the first rectangle such that at least 1 side is equal and that side overlaps of both the rectangles a
7 min read
Maximum area of a Rectangle that can be circumscribed about a given Rectangle of size LxW
Given a rectangle of dimensions L and W. The task is to find the maximum area of a rectangle that can be circumscribed about a given rectangle with dimensions L and W. Examples: Input: L = 10, W = 10Output: 200 Input: L = 18, W = 12Output: 450 Approach: Let below is the given rectangle EFGH of dimensions L and W. We have to find the area of rectang
4 min read
Program to find Perimeter / Circumference of Square and Rectangle
The circumference of a figure is the sum of all the side lengths. To calculate the circumference of square, length of one of the side is required as all sides are equal. To calculate the circumference of rectangle, length and breadth of rectangle is required. Circumference of a Square:   The circumference of a square is given by the formula:   C =
5 min read
Program to calculate area and perimeter of Trapezium
A trapezium is a quadrilateral with at least one pair of parallel sides, other two sides may not be parallel. The parallel sides are called the bases of the trapezium and the other two sides are called it's legs. The perpendicular distance between parallel sides is called height of trapezium. Formula : Area of Trapezium : 0.5 * (a + b) * h Perimete
5 min read
Program to calculate area and perimeter of equilateral triangle
An equilateral triangle is a triangle in which all three sides and angles are equal. All three internal angles of equilateral triangle measures 60 degree. If we know the length of each sides of equilateral triangle, then we can use below mentioned formula to calculate area of equilateral triangle.Area of Equilateral Triangle = (sqrt(3)/4) * a * a I
4 min read
Program to find the Area and Perimeter of a Semicircle
Given the radius of the semicircle as r, the task is to find out the Area and Perimeter of that semicircle.Examples: Input: r = 10 Output: Area = 157.00, Perimeter = 31.4 Input: r = 25 Output: Area =981.250000, Perimeter = 78.500000 Approach: In mathematics, a semicircle is a one-dimensional locus of points that forms half of a circle. The area of
5 min read
Program to calculate area and perimeter of a rhombus whose diagonals are given
Given the length of diagonals of a rhombus, d1 and d2. The task is to find the perimeter and the area of that rhombus. A rhombus is a polygon having 4 equal sides in which both the opposite sides are parallel, and opposite angles are equal. Examples: Input: d1 = 2 and d2 = 4 Output: The area of rhombus with diagonals 2 and 4 is 4. The perimeter of
5 min read
Program to calculate the Area and Perimeter of Incircle of an Equilateral Triangle
Given the length of sides of an equilateral triangle, the task is to find the area and perimeter of Incircle of the given equilateral triangle. Examples: Input: side = 6 Output: Area = 9.4. Perimeter = 10.88 Input: side = 9 Output: Area = 21.21, Perimeter = 16.32 Properties of an Incircle are: The center of the Incircle is same as the center of the
4 min read