public
Created

Simplify ratio

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.