Problem with Pythagorean triple etc.
You can probably tell by the title of the topic that this is basically a homework problem. Anyway, for some reason I am having a brain fart or something because I am not able to work it out. Specifically this is what I have to do:
(Pythagorean Triples) A right triangle can have sides that are all integers. The set of three integer values for the sides of a right triangle is called a Pythagorean triple. These three sides must satisfy the relationship that the sum of the squares of two of the sides is equal to the square of the hypotenuse. Find all Pythagorean triples for side1, side2, and the hypotenuse all no larger than 500. Use a triple-nested for loop that simply tries all possibilities.
If someone could just point me in the right direction and slap me across the face while you do that, that would be great thanks!
Code:
#include <stdio.h>
void main()
{
int result;
int tenuse;
for (int side1 = 0; side1 < 500; side1++)
{
for (int side2 = 0; side2 < 500; side2++)
{
for (int hypo = 1; hypo <= 500; hypo++)
{
result = side1 * side1 + side2 * side2;
tenuse = hypo * hypo;
if(result == hypo)
printf("%d %d %d", side1, side2, hypo);
printf("\n");
}
}
}
}