Skip to content

Instantly share code, notes, and snippets.

@xigh
Created December 24, 2018 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xigh/180e49dbbcc8e97da632a4f057155ecc to your computer and use it in GitHub Desktop.
Save xigh/180e49dbbcc8e97da632a4f057155ecc to your computer and use it in GitHub Desktop.
Pythagorian Triples, the old way
#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