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.

 

Solution:

#include <bits/stdc++.h>

using namespace std;

int main(){

int l1,l2,w1,w2;

cout<<“Enter length of 1st rectangle : “;

cin>>l1;

cout<<“Enter width of 1st rectangle : “;

cin>>w1;

cout<<“Enter length of 2nd rectangle : “;

cin>>l2;

cout<<“Enter width of 2nd rectangle : “;

cin>>w2;

int a1=l1*w1;

int a2=l2*w2;

if(a1>a2){

cout<<“First rectangle has greater area compared to second rectangle.”<<endl;

}

else if(a1==a2){

cout<<“First rectangle and second rectangle have same area.”<<endl;

}

else{

cout<<“Second rectangle has greater area compared to first rectangle.”<<endl;

}

return 0;

}