Program for Area And Perimeter Of Rectangle

21 Jun, 2022
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++
Java
Python3
C#
PHP
Javascript
// CPP program to find area// and perimeter of rectangle#include<bits/stdc++.h>using namespace std; // Utility functionint 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 programint main(){  int a = 5;  int b = 6;  cout << "Area = " << areaRectangle(a, b) << endl;  cout << "Perimeter = " << perimeterRectangle(a, b);  return 0;}
// Java program to find area// and perimeter of rectangleimport 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 code to find area# and perimeter of rectangle # Utility functiondef areaRectangle(a, b):    return (a * b) def perimeterRectangle(a, b):    return (2 * (a + b)) # Driver functiona = 5;b = 6;print ("Area = ", areaRectangle(a, b))print ("Perimeter = ", perimeterRectangle(a, b)) # This code is contributed by 'saloni1297'.
// C# program to find area// and perimeter of rectangleusing 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 program to find area// and perimeter of rectangle // Utility functionfunction 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.?>
<script> // Javascript program to find area// and perimeter of rectangle // Utility functionfunction 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)
This article is contributed by Saloni Gupta. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. 
vt_m
mank1083
kk773572498
krishnav4
area-volume-programs
Geometric
School Programming
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.