Answer to Question #72143 in C++ for awais ali

Question #72143
In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides. Write a program that prompts the user to enter the lengths of three sides of a triangle and then outputs a message indicating whether the triangle is a right triangle.
1
Expert's answer
2017-12-27T04:24:46-0500
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
double x1, x2, x3;
cout << "Input the lengths of three sides of a triangle: \n";
cout << "side 1: ";
cin >> x1;
cout << "side 2: ";
cin >> x2;
cout << "side 3: ";
cin >> x3;

bool isRight = false;

if (pow(x1, 2) == pow(x2, 2) + pow(x3, 2)) isRight = true;
if (pow(x2, 2) == pow(x1, 2) + pow(x3, 2)) isRight = true;
if (pow(x3, 2) == pow(x2, 2) + pow(x1, 2)) isRight = true;

if (isRight) cout << "The triangle is a right triangle.\n";
else cout << "The triangle isn't a right triangle.\n";

system("pause");

return 0;
}

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS