101k views
5 votes
The area 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 areas are the same.

1 Answer

4 votes

Answer:

Using c++

Check the image for colors.

Explanation:

#include <iostream>

using namespace std;

int main()

{

float length1,length2,width1,width2,area1,area2;

cout<<"length of Rectangle 1\\";

cin>>length1;

cout<<"\\width of Rectangle 1\\";

cin>>width1;

cout<<"\\lenght of Rectangle 2\\";

cin>>length2;

cout<<"\\width of Rectangle 2\\";

cin>>width2;

area1=length1*width1;

area2=length2*width2;

if (area1<area2)

{cout << "\\Rectangle 2 has greater area";}

else {

if (area1>area2)

{cout << "\\Rectangle 1 has greater area";}

else {cout << "\\Areas are the same";}

}

return 0;

}

The area of a rectangle is the rectangle’s length times its width. Write a program-example-1
User Chena
by
3.5k points