Program to find area and peremeter of rectangle

Program to find area and peremeter of rectangle

  • Write a program to find area and peremeter of rectangle in C
  • Write a program to find area and peremeter of rectangle in C++
  • Write a program to find area and peremeter of rectangle in Python
  • Write a program to find area and peremeter of rectangle in PHP
  • Write a program to find area and peremeter of rectangle in Java
  • Write a program to find area and peremeter of rectangle in Java Script
  • Write a program to find area and peremeter of rectangle in C#

Explanation:

Any quadrilateral with equal opposed sides and all angles equal to 90 degrees is called a rectangle.

Formulas:

  1. Area (A): Area = Length x Width
  2. Perimeter (P): Perimeter = 2 x (Length + Width)

Program to find area and peremeter of rectangle

#include <stdio.h>

int main() {
    float length, width, area, perimeter;

    printf("Enter the length of the rectangle: ");
    scanf("%f", &length);

    printf("Enter the width of the rectangle: ");
    scanf("%f", &width);

    area = length * width;
    perimeter = 2 * (length + width);

    printf("Area of the rectangle: %.2f\n", area);
    printf("Perimeter of the rectangle: %.2f\n", perimeter);

    return 0;
}

#include <iostream>
using namespace std;

int main() {
    double length, width, area, perimeter;

    cout << "Enter the length of the rectangle: ";
    cin >> length;

    cout << "Enter the width of the rectangle: ";
    cin >> width;

    area = length * width;
    perimeter = 2 * (length + width);

    cout << "Area of the rectangle: " << area << endl;
    cout << "Perimeter of the rectangle: " << perimeter << endl;

    return 0;
}

length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))

area = length * width
perimeter = 2 * (length + width)

print(f"Area of the rectangle: {area:.2f}")
print(f"Perimeter of the rectangle: {perimeter:.2f}")

<?php
echo "Enter the length of the rectangle: ";
$length = (float)readline();

echo "Enter the width of the rectangle: ";
$width = (float)readline();

$area = $length * $width;
$perimeter = 2 * ($length + $width);

echo "Area of the rectangle: " . number_format($area, 2) . "\n";
echo "Perimeter of the rectangle: " . number_format($perimeter, 2) . "\n";
?>

import java.util.Scanner;

public class RectangleProperties {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the length of the rectangle: ");
        double length = scanner.nextDouble();

        System.out.print("Enter the width of the rectangle: ");
        double width = scanner.nextDouble();

        double area = length * width;
        double perimeter = 2 * (length + width);

        System.out.printf("Area of the rectangle: %.2f\n", area);
        System.out.printf("Perimeter of the rectangle: %.2f\n", perimeter);

        scanner.close();
    }
}

const length = parseFloat(prompt("Enter the length of the rectangle:"));
const width = parseFloat(prompt("Enter the width of the rectangle:"));

const area = length * width;
const perimeter = 2 * (length + width);

console.log(`Area of the rectangle: ${area.toFixed(2)}`);
console.log(`Perimeter of the rectangle: ${perimeter.toFixed(2)}`);

using System;

class Program {
    static void Main() {
        Console.Write("Enter the length of the rectangle: ");
        double length = Convert.ToDouble(Console.ReadLine());

        Console.Write("Enter the width of the rectangle: ");
        double width = Convert.ToDouble(Console.ReadLine());

        double area = length * width;
        double perimeter = 2 * (length + width);

        Console.WriteLine($"Area of the rectangle: {area:F2}");
        Console.WriteLine($"Perimeter of the rectangle: {perimeter:F2}");
    }
}

List of All Programs