10. Triangle

topic:

3 input triangle side length values ​​(both positive integers), it is determined whether the length of three sides of a right triangle. If so, then the output yes, if not, the output no. If you can not form a triangle, the output is not a triangle.

Ideas:

Determining whether the first three sides of a generally triangular configuration, and if so, determines whether to continue right triangle configuration.

Code:

#include <iostream>
using namespace std;

int main()
{
int a = 0, b = 0, c = 0;
cin >> a >> b >> c;

if ((a + b > c) && (a + c > b) && (b + c > a)) {
if ((a * a + b * b == c * c) || (a * a + c * c == b * b) || (b * b + c * c == a * a)) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
} else {
cout << "not a triangle" << endl;
}

return 0;
}

Guess you like

Origin www.cnblogs.com/Hello-Nolan/p/12110220.html