Monday, February 10, 2020

Find the Area and Perimeter of a Rectangle in C++/Java Program


 
Image result for Perimeter of a Rectangle concept?
 
 

Area and Perimeter of a Rectangle in C++ Program 

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
float area,perimeter,w,l;
cout<<"Enter Width of Rectancle";
cin>>w;
cout<<"Enter Length of Rectancle";
cin>>l;
area=w*l;
perimeter=2*(l+w);
cout<<" Area of a Rectangle:"<<area;
cout<<" perimeter of a Rectangle:"<<perimeter;
getch();
}

Area and Perimeter of a Rectangle in Java Program 


  import java.util.Scanner;
class AP
{
public static void main(String []args)
{
Scanner  obj=new Scanner(System.in);
float area,perimeter,w,l;
System.out.print("   Enter Width of Rectancle   :");
w=obj.nextFloat();
System.out.print("  Enter Length of Rectancle  :");
l=obj.nextFloat();
area=w*l;
perimeter=2*(l+w);
System.out.println("  Area of a Rectangle  :"  +area);
System.out.println("  perimeter of Rectangle  :" +perimeter);
}
}

No comments:

Post a Comment