矩形是平面中的平面图形,它具有四个边和四个相等的90度角,在矩形中,所有四个边的长度不如正方形,彼此相对的边具有相等的长度。长度相等。
例子:
Input : 4 5
Output : Area = 20
Perimeter = 18
Input : 2 3
Output : Area = 6
Perimeter = 10
公式:
Area of rectangle : a*b
Perimeter of ractangle: 2*(a + b)
C++
// CPP program to find area
// and perimeter of rectangle
#include
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
Javascript
输出 :
Area = 30
Perimeter = 22