Problem statement:- Program to calculate the area and perimeter of a rectangle.
Data requirement:-
Input Data:-length,breadth
Output Data:-area, perimeter
Output Data:-area, perimeter
Program in C
Here is the source code of the C Program to Program to calculate the area and perimeter of a rectangle.
Code:
#include<stdio.h>
int main(){
double length,breadth;
double area, perimeter;
printf("Enter the length of rectangle:");
scanf("%lf",&length);
printf("Enter the breadth of rectangle:");
scanf("%lf",&breadth);
area=length*breadth;
perimeter=2*(length+breadth);
printf("Area of the rectangle = %0.2lf",area);
printf("\nPerimeter of the rectangle = %0.2lf",perimeter);
return 0;
}
Input/Output:
Enter the length of rectangle:5
Enter the breadth of rectangle:4
Area of the rectangle = 20.00
Perimeter of the rectangle = 18.00
Area of the rectangle = 20.00
Perimeter of the rectangle = 18.00
Program in C++
Here is the source code of the C++ Program to Program to Find the area and perimeter of a rectangle.
Code:
#include<iostream>
using namespace std;
int main()
{
double length,breadth;
double area, perimeter;
cout<<"Enter the length of rectangle:";
cin>>length;
cout<<"Enter the breadth of rectangle:";
cin>>breadth;
area=length*breadth;
perimeter=2*(length+breadth);
cout<<"Area = "<<area;
cout<<"\nPerimeter = "<<perimeter;
return 0;
}
using namespace std;
int main()
{
double length,breadth;
double area, perimeter;
cout<<"Enter the length of rectangle:";
cin>>length;
cout<<"Enter the breadth of rectangle:";
cin>>breadth;
area=length*breadth;
perimeter=2*(length+breadth);
cout<<"Area = "<<area;
cout<<"\nPerimeter = "<<perimeter;
return 0;
}
Input/Output:
Enter the length of rectangle:7
Enter the breadth of rectangle:3
Area = 21
Perimeter = 20
Area = 21
Perimeter = 20
Program in Java
Here is the source code of the Java Program to Program to calculate the area and perimeter of a rectangle.
Code:
import java.util.Scanner;
public class AreaPerimeterRectangle {public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
double length,breadth;
double area, perimeter;
System.out.println("Enter the length of rectangle:");
length=cs.nextDouble();
System.out.println("Enter the breadth of rectangle:");
breadth=cs.nextDouble();
area=length*breadth;
perimeter=2*(length+breadth);
System.out.println("Area of the rectangle = "+area);
System.out.println("Perimeter of the rectangle = "+perimeter);
cs.close();
}
}
Input/Output:
Enter the length of rectangle:
7.5
Enter the breadth of rectangle:
8.0
Area of the rectangle = 60.0
Perimeter of the rectangle = 31.0
7.5
Enter the breadth of rectangle:
8.0
Area of the rectangle = 60.0
Perimeter of the rectangle = 31.0
Program in Python
Here is the source code of the Python Program to Program to Find the area and perimeter of a rectangle.
Code:
length=int(input("Enter length of a rectangle :"))
breadth=int(input("Enter breadth of a rectangle :"))
area=length*breadth
perimeter=2*(length+breadth)
print("Area =",area)
print("Perimeter =",perimeter)
breadth=int(input("Enter breadth of a rectangle :"))
area=length*breadth
perimeter=2*(length+breadth)
print("Area =",area)
print("Perimeter =",perimeter)
Input/Output:
Enter length of a rectangle :8
Enter breadth of a rectangle :5
Area = 40
Perimeter = 26
Enter breadth of a rectangle :5
Area = 40
Perimeter = 26
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box