Skip to content

Instantly share code, notes, and snippets.

@xigh xigh/pyth.c
Created Dec 24, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.