(Sides of a Right Triangle) Write a program that reads three nonzero integers and determines and prints whether they’re the sides of a right triangle.
using namespace std;
int main()
{
int a, b, c;
cout << "Enter three numbers: " << endl;
cin >> a >> b >> c;
if( (a*a + b*b == c*c) | | ( b*b + c*c == a*a ) | | ( c*c + a*a == b*b ) )
cout << "they are the sides of a right triangle" << endl;
else
cout << "they are NOT the sides of a right triangle" << endl;
//for pause
system("PAUSE") ;
return 0;
}
Solution:
#include < iostream>using namespace std;
int main()
{
int a, b, c;
cout << "Enter three numbers: " << endl;
cin >> a >> b >> c;
if( (a*a + b*b == c*c) | | ( b*b + c*c == a*a ) | | ( c*c + a*a == b*b ) )
cout << "they are the sides of a right triangle" << endl;
else
cout << "they are NOT the sides of a right triangle" << endl;
//for pause
system("PAUSE") ;
return 0;
}
Post A Comment:
0 comments: