68 774
Assignments Done
Successfully Done
In January 2019

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.
Expert's answer
#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";


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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions