Created
October 23, 2013 05:22
-
-
Save gubatron/7112985 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 "brilliant.h" | |
| #define true 1 | |
| #define false 0 | |
| int gcd(int a, int b) { | |
| int c; | |
| while (a!=0) { | |
| c=a; | |
| a=b%a; | |
| b=c; | |
| } | |
| return b; | |
| } | |
| int gcd3(int a, int b, int c) { | |
| return gcd(gcd(a,b),c); | |
| } | |
| int reverse(int n) { | |
| int result = 0; | |
| while (n > 0) { | |
| result = result * 10 + n%10; | |
| n = n/10; | |
| } | |
| return result; | |
| } | |
| int isPrime(int n) { | |
| int i; | |
| for (i=1; i<n; i++) { | |
| if (n % i == 0 && i!=1) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| }; |
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
| #ifndef BRILLIANT_H | |
| #define BRILLIANT_H | |
| //greatest common divisor | |
| int gcd(int a, int b); | |
| int gcd3(int a, int b, int c); | |
| //reverse integer | |
| int reverse(int n); | |
| //is prime | |
| int isPrime(int n); | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment