Skip to content

Instantly share code, notes, and snippets.

@gubatron
Created October 23, 2013 05:22
Show Gist options
  • Select an option

  • Save gubatron/7112985 to your computer and use it in GitHub Desktop.

Select an option

Save gubatron/7112985 to your computer and use it in GitHub Desktop.
#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;
};
#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