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 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 ractangle: 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; } |
python
# 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'. |
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 |
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. ?> |
Output :
Area = 30 Perimeter = 22
This article is contributed by Saloni Gupta. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Maximum area of rectangle possible with given perimeter
- Ratio of area of a rectangle with the rectangle inscribed in it
- Maximum area of a Rectangle that can be circumscribed about a given Rectangle of size LxW
- Program to find Perimeter / Circumference of Square and Rectangle
- Program to calculate area and perimeter of Trapezium
- Program to calculate area and perimeter of equilateral triangle
- Program to find the Area and Perimeter of a Semicircle
- Program to calculate area and perimeter of a rhombus whose diagonals are given
- Program to calculate the Area and Perimeter of Incircle of an Equilateral Triangle
- Program to find all possible triangles having same Area and Perimeter
- Perimeter and Area of Varignon's Parallelogram
- Area of a Square | Using Side, Diagonal and Perimeter
- Find maximum volume of a cuboid from the given perimeter and area
- Largest subset of rectangles such that no rectangle fit in any other rectangle
- Area of the largest rectangle formed by lines parallel to X and Y axis from given set of points
- Maximum area rectangle by picking four sides from array
- Area of a triangle inscribed in a rectangle which is inscribed in an ellipse
- Area of the biggest possible rhombus that can be inscribed in a rectangle
- Find minimum area of rectangle with given set of coordinates
- Number of squares of maximum area in a rectangle
Improved By : vt_m

