Question #4839

the are of a rectangle is the rectangle's length times its width. Write a program that asks for the length and width of two rectangles. the program should tell the user which rectangle has the greater area, or if the ares are the same.

Expert's answer

#include <iostream.h>

#include <conio.h>

main(){

float a1,b1,a2,b2,s1,s2;

cout<<"Enter the lenght of the first rectangle:";

cin>>a1;

cout<<"Enter the width of the first rectangle:";

cin>>b1;

cout<<"Enter the lenght of the second rectangle:";

cin>>a2;

cout<<"Enter the width of the second rectangle:";

cin>>b2;

s1 = a1*b1;

s2 = a2*b2;

if (s1>s2) cout<<"First rectangle is larger than the second";

if (s1<s2) cout<<"Second rectangle is larger than the first";

if (s1==s2) cout<<"Rectangles has equal areas";

getch();

}

#include <conio.h>

main(){

float a1,b1,a2,b2,s1,s2;

cout<<"Enter the lenght of the first rectangle:";

cin>>a1;

cout<<"Enter the width of the first rectangle:";

cin>>b1;

cout<<"Enter the lenght of the second rectangle:";

cin>>a2;

cout<<"Enter the width of the second rectangle:";

cin>>b2;

s1 = a1*b1;

s2 = a2*b2;

if (s1>s2) cout<<"First rectangle is larger than the second";

if (s1<s2) cout<<"Second rectangle is larger than the first";

if (s1==s2) cout<<"Rectangles has equal areas";

getch();

}

Learn more about our help with Assignments: C++

## Comments

## Leave a comment