I recently encountered a Stack Overflow question (since closed) in which the OP was testing for whether a triangle was right by whether or not it "met" the criteria of the Pythagorean Theorem (i.e. whether or not the square of the hypotenuse is equal to the square of the two sides). The code was to this effect:
public void Test(int a, int b, int c) {
if ((c * c) == ((a * a) + (b * b)) {
System.out.println("This is a right triangle");
}
else {
System.out.println("This is not a right triangle");
}
}
(There are obviously some other problems with this code, like the fact that it doesn't validate the input to make sure that the inputs are positive and the fact that it only accepts integers).
The question was asking about something completely different in the code and never directly addressed the test, but I got to thinking: is this a valid test for whether a triangle is a right triangle?
Obviously, the Pythagorean Theorem states that, for all right triangles, $a^2 + b^2 = c^2$ (where $a$ and $b$ are sides and $c$ is the hypotenuse). This will hold for all right triangles, so being a right triangle is a sufficient condition for the Pythagorean Theorem to hold.
Is it also a necessary condition? I.e. if $c^2 = a^2 + b^2$ for some arbitrary triangle, is the triangle necessarily a right triangle? Or are there counterexamples?