Playing along at home, this is what I had.
#include <stdio.h>
int main(void)
{
int a, b, c, i = 0, limit = 500;
puts("Pythagorean Triples:");
for ( a = 1; a < limit; ++a )
{
for ( b = a + 1; b < limit; ++b )
{
for ( c = b + 1; c < limit; ++c )
{
if ( a * a + b * b == c * c )
{
printf("%3d : { %3d, %3d, %3d }\n", ++i, a, b, c);
}
}
}
}
return 0;
}
The first several outputs are as follows.Pythagorean Triples:
1 : { 3, 4, 5 }
2 : { 5, 12, 13 }
3 : { 6, 8, 10 }
4 : { 7, 24, 25 }
5 : { 8, 15, 17 }
6 : { 9, 12, 15 }
7 : { 9, 40, 41 }
8 : { 10, 24, 26 }
9 : { 11, 60, 61 }
10 : { 12, 16, 20 }
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314