Not easily:
First you have to create a method that finds all factors of a given number and output them as a IEnumerable<int>
public IEnumerable<int> Factorize(int number) {
int max = (int)(number/2);
for(int factor = 1; factor <= max; ++factor) {
if(number % factor == 0) {
yield return factor;
}
}
yield number;
}
</int>
Now you have the factors, you need to find factors common to both numbers (common denominator)
public IEnumerable<int> CommonDenominators(int numberLeft,int NumberRight) {
return Factorize(numberLeft).Union(Factorize(numberRight);
}
</int>
Actually:,You can adapt that to return the highest (i always thought is was the lowest, which would be 1?) common denominator:
public int HighestCommonDenominator(int numberLeft,int NumberRight) {
return Factorize(numberLeft).Union(Factorize(numberRight).Max(n=>n);
}
Edit: If there are no other common denominators, i.e. 17:181 then the number 1 will be returned, so it's still accurate
Then just divide both numbers by that number:
int left = 550;
int right = 150:
int highestCommonDenominator = HighestCommonDenominator(left, right );
int lowestLeft = left / lowestCommonDenominator;
int lowestRight = right / lowestCommonDenominator;
I haven't tested the code but the essentials are there
Hope that helps :)