Program to find area and peremeter of square

Program to find area and peremeter of square

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

Explanation:

A square is a particular kind of rectangle in which every angle is 90 degrees and every side is the same length.

Formulas:

  1. Area (A): Area = Side x Side, Where “Side” is the length of one side of the square.
  2. Perimeter (P): Perimeter = 4 × Side

Program to find area and peremeter of square

#include <stdio.h>

int main() {
    float side, area, perimeter;

    printf("Enter the side of the square: ");
    scanf("%f", &side);

    area = side * side;
    perimeter = 4 * side;

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

    return 0;
}

#include <iostream>
using namespace std;

int main() {
    double side, area, perimeter;

    cout << "Enter the side of the square: ";
    cin >> side;

    area = side * side;
    perimeter = 4 * side;

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

    return 0;
}

side = float(input("Enter the side of the square: "))

area = side ** 2
perimeter = 4 * side

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

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

$area = $side * $side;
$perimeter = 4 * $side;

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

import java.util.Scanner;

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

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

        double area = side * side;
        double perimeter = 4 * side;

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

        scanner.close();
    }
}

const side = parseFloat(prompt("Enter the side of the square:"));

const area = side * side;
const perimeter = 4 * side;

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

using System;

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

        double area = side * side;
        double perimeter = 4 * side;

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

List of All Programs