Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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