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.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double first,second,third;
cout << "Enter the length of three sides. " << endl;
cin >> first >> second >>third;
if(pow(third,2)-pow(second,2)-pow(first,2) == 0)
cout << "The triangle is a right triangle " << endl;
else if (pow(second,2)-pow(first,2)+pow(third,2) == 0 )
cout << "The triangle is a right triangle" << endl;
else if (pow(third,2) -pow(second,2)+pow(first,2)==0 )
cout << "The triangle is a right triangle" << endl;
else
cout << "The triangle is not a right triangle. " << endl;
return 0;
}
Comments
Leave a comment