Question #246759

The circumference of a rectangle is 2*(length + width), where length and width are

length and width of the rectangle. Write a program that asks for the length and width of

two rectangles. The program should tell the user which rectangle has the greater

circumference, or if the circumferences are the same


Expert's answer

Source code


#include <iostream>


using namespace std;


int main()
{
    int length_A;
    int width_A;
    int length_B;
    int width_B;
    cout<<"\nEnter details for rectangle A: \n";
    cout<<"\nLength: ";
    cin>>length_A;
    cout<<"\nWidth: ";
    cin>>width_A;
    
    cout<<"\nEnter details for rectangle B: \n";
    cout<<"\nLength: ";
    cin>>length_B;
    cout<<"\nWidth: ";
    cin>>width_B;
    
    int circ_A=2*(length_A+width_A);
    int circ_B=2*(length_B+width_B);
    
    if(circ_A>circ_B){
        cout<<"\nRectangle A has greater circumference";
    }
    else if(circ_B>circ_A){
        cout<<"\nRectangle B has greater circumference";
    }
    else{
        cout<<"\nThe circumferences are the same";
    }
    return 0;
}



Sample Output 1




Sample Output 2




Sample Output 3





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS