Answer to Question #142854 in C++ for rob

Question #142854

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.

 

 

****Run program for a 5, 12,13 and again for 7, 9,20 (2 screenshots)


1
Expert's answer
2020-11-09T00:10:44-0500
#include <iostream>

int main()
{
   std::cout << "Enter the lengths of three sides of a triangle:";
   float a, b, c;
   std::cin >> a >> b >> c;

   if ((a * a == b * b + c * c) || (b * b == a * a + c * c) || (c * c == a * a + b * b))
     std::cout << "The triangle is a right triangle" << std::endl;
   else
     std::cout << "The triangle is not a right triangle" << std::endl;
}

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