TITLE: Is being a right triangle both necessary and sufficient for the Pythagorean Theorem to hold?
QUESTION [44 upvotes]: 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?

REPLY [5 votes]: Yes, and this goes back to Euclid.   Euclid I.47 is "In right-angled triangles the square on the side opposite the right angle equals the sum of the squares on the sides containing the right angle."  Euclid I.48 is the converse, "If in a triangle the square on one of the sides equals the sum of the squares on the remaining two sides of the triangle, then the angle contained by the remaining two sides of the triangle is right."