1 Attachment(s)

Pythagorean Triples program

Hello,

I am writing a basic program in C whose function is to print all the Pythagorean Triples like these:

3,4,5

6,8,10

5,12,13

...

all the way up to 45.

This is my code:

Code:

#include <stdio.h>

int main()

{

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);

}

LegOne++;

}

LegTwo++;

}

Hypotenuse++;

}

printf(\n\n);

}

This code gives me this output:

Attachment 10980

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.