Created
December 24, 2018 08:19
-
-
Save xigh/180e49dbbcc8e97da632a4f057155ecc to your computer and use it in GitHub Desktop.
Pythagorian Triples, the old way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int c = 1, n = 0; | |
while (n < 10) | |
{ | |
int c2 = c * c; | |
for (int a = 1; a < c; a++) | |
{ | |
int a2 = a * a; | |
for (int b = a; b < c; b++) // b >= a to avoid duplicates | |
{ | |
int b2 = b * b; | |
if (c2 == (a2 + b2)) | |
{ | |
n++; | |
printf("(%d,%d,%d)\n", a, b, c); | |
} | |
} | |
} | |
c++; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment