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)
#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;
}
Comments
Leave a comment