Program to Find area and perimeter of a square

Problem statement:- Program to Find the area and perimeter of a square.

Data requirement:-

   Input Data:-side

  Output Data:-
area

Program in C

Here is the source code of the C Program to Find the area and perimeter of a square.

Code:

#include <stdio.h>
int main()
{
    double side;
    double area,perimeter;

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

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

   printf("Area of the square = %lf",area);
   printf("\nPerimeter of the square= %lf",perimeter);

    return 0;
}

Input/Output:
Enter the side of square:7
Area of the square = 49.00
Perimeter of the square= 28.00


Program in C++

Here is the source code of the C++ Program to Find the area and perimeter of a square.

Code:

#include <iostream>
using namespace std;
int main()
{
    double side;
    double area,perimeter;

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

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

    cout<<"Area of the square = "<<area;
    cout<<"\nPerimeter of the square= "<<perimeter;

    return 0;
}

Input/Output:
Enter the side of square:3.5
Area of the square = 12.25
Perimeter of the square= 14

Program in Java

Here is the source code of the Java Program to Find the area and perimeter of a square.

Code:

import java.util.Scanner;
public class AreaPerimeterSquare {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
    double side;
    double area,perimeter;

    System.out.println("Enter the side of square:");
    side=cs.nextDouble();

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

   System.out.println("Area of the square = "+area);
   System.out.println("\nPerimeter of the square= "+perimeter);

  cs.close();
}}

Input/Output:
Enter the side of square:
5
Area of the square = 25.0
Perimeter of the square= 20.0

Program in Python

Here is the source code of the Python Program to Find the area and perimeter of a square.

Code:

side=int(input("Enter side of a square :"))
area=side*side
perimeter=4*side

print("Area of the Square=",area)
print("Perimeter of the square=",perimeter)

Input/Output:
Enter the side of square:3.5
Area of the square = 12.25
Perimeter of the square= 14



Post a Comment

0 Comments