Skip to content

Instantly share code, notes, and snippets.

@jinthagerman
Created November 23, 2012 02:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jinthagerman/4133720 to your computer and use it in GitHub Desktop.
Simplify ratio
int n1 = 320;
int n2 = 480;
simplifyRatio(&n1, &n2);
printf("%d %d", &n1, &n2);
int highestCommonFactor(int n1, int n2) {
int remainder = n1%n2;
if (remainder != 0) {
return highestCommonFactor(n2, remainder);
} else {
return n2;
}
}
void simplifyRatio(int* n1, int* n2) {
int HCF = highestCommonFactor(*n1, *n2);
*n1 = *n1/HCF;
*n2 = *n2/HCF;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment