I am writing a basic program in C whose function is to print all the Pythagorean Triples like these:
all the way up to 45.
This is my code:
This code gives me this output:
int LegOne, LegTwo, Hypotenuse;
Hypotenuse = 0;
while ( Hypotenuse < 50 )
LegTwo = 1;
while ( LegTwo < 50 )
LegOne = 1;
while ( LegOne < 50 )
if ( LegOne*LegOne + LegTwo*LegTwo == Hypotenuse*Hypotenuse && LegOne < LegTwo )
printf("\n\t\t The sides are %4d,%4d,%4d", LegOne,LegTwo,Hypotenuse);
As you can see, the numbers to the far left are not in order, they are scrambled all over the place. Is there a way to make the left numbers in ascending order without using "pow"? Thanks a lot.