I want to write a code in C language to output a list of triples matching the Pythagorean triple in a range of positive integers (a2 = b2 + c2 with a, b and c ∈ ℤ+) using only nested while ()
loops.
I wrote this:
//Programme to output possible Pythagorean triples in a range of unsigned integers.
#include <stdio.h>
int main(void) {
unsigned int i = 1, j = 1, ij = 1;
puts("\n***To calculate Pythag. triple integers...***\n");
while (i <= 250) {
while (j <= 250) {
while (ij <= 250) {
if (ij * ij == i * i + j * j) {
printf ("Candidate triple: (%u, %u, %u)\n", ij, i, j);
}
++ij;
}
++j;
}
++i;
}
return 0;
}
It does not work. It only shows the text in the first puts()
function.
output:
What's my mistake?