(Sides of a Right Triangle) Write a program that reads three nonzero integers and deter- mines and prints whether they could be the sides of a right triangle.
What will be an ideal response?
```
// Determine whether three values represent the sides of a right triangle.
#include
using namespace std;
int main()
{
int side1; // length of side 1
int side2; // length of side 2
int side3; // length of side 3
bool isRightTriangle = false; // if sides can form right triangle
// get values of three sides
cout << "Enter side 1: ";
cin >> side1;
cout << "Enter side 2: ";
cin >> side2;
cout << "Enter side 3: ";
cin >> side3;
// square the sides
int side1Square = side1 * side1;
int side2Square = side2 * side2;
int side3Square = side3 * side3;
// test if sides can form a right triangle
if ( ( side1Square + side2Square ) == side3Square )
isRightTriangle = true;
else if ( ( side1Square + side3Square ) == side2Square )
isRightTriangle = true;
else if ( ( side2Square + side3Square ) == side1Square )
isRightTriangle = true;
// display results
if ( isRightTriangle )
cout << "These are the sides of a right triangle." << endl;
else
cout << "These do not form a right triangle." << endl;
} // end main
```
You might also like to view...
A(n) ___________________ consists of a set of data and a set of operations that act upon that data.
A. data type B. user data type C. operative data type D. abstract data type
Describe the process for developing an effective list of site goals.
What will be an ideal response?
Which of the following regular expression metacharacters matches any numeric character?
A. \d B. \D C. \s D. \S
Access identifies dates by enclosing them in ________.
What will be an ideal response?