Created
November 6, 2008 15:18
-
-
Save benhoskings/22608 to your computer and use it in GitHub Desktop.
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> | |
| #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