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.
#include <iostream>
using namespace std;
int main()
{
int w1, w2, h1, h2, p1, p2;
cout << "Input width and height of the first rectangle: ";
cin >> w1 >> h1;
cout << "Input width and height of the second rectangle: ";
cin >> w2 >> h2;
p1 = 2 * (w1 + h1);
p2 = 2 * (w2 + h2);
if (p1 == p2)
cout << "Same circumference\n";
else if (p1 > p2)
cout << "The first rectangle";
else
cout << "The second rectangle\n";
return 0;
}
Example:
Input width and height of the first rectangle: 1 2
Input width and height of the second rectangle: 3 4
The second rectangle
Comments
Leave a comment