Skip to content

Instantly share code, notes, and snippets.

@benhoskings
Created November 6, 2008 15:18
Show Gist options
  • Select an option

  • Save benhoskings/22608 to your computer and use it in GitHub Desktop.

Select an option

Save benhoskings/22608 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
bool rightTriangle(int a, int b, int c) {
return a*a == b*b + c*c;
}
void printTriangle(int a, int b, int c, bool printed) {
printf("%s[(%i),(%i),(%i)]", (printed ? "," : ""), a, b, c);
}
int main(int argc, char **argv) {
int a, b, c;
bool printed = false;
for (a = 1; a <= 500; a++) {
for (b = 1; b <= a; b++) {
for (c = 1; c <= b; c++) {
if (rightTriangle(a, b, c)) {
printTriangle(a, b, c, printed);
printed = true;
}
}
}
}
if (printed) {
printf("\n");
}
return(EXIT_SUCCESS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment