コード例 #1
0
        public Fraction SubtractFraction(Fraction f)
        {
            //get common denominator
            var commonDenominator = _denominator * f.GetDenominator();
            var addition          = (_numerator * (_denominator / commonDenominator)) - (f.GetNumerator() * (f.GetDenominator() / commonDenominator));

            return(new Fraction(addition, commonDenominator));
        }
コード例 #2
0
        public Fraction AddFraction(Fraction f)
        {
            //get common denominator
            var commonDenominator = _denominator * f.GetDenominator();
            var addition          = (_numerator * (commonDenominator / _denominator)) + (f.GetNumerator() * (commonDenominator / f.GetDenominator()));

            return(new Fraction(addition, commonDenominator));
        }
コード例 #3
0
 public Fraction DivideFraction(Fraction f)
 {
     //switch numerator/denominator on f and multiply
     return(MultiplyFraction(new Fraction(f.GetDenominator(), f.GetNumerator())));
 }
コード例 #4
0
 public Fraction MultiplyFraction(Fraction f)
 {
     return(new Fraction(_numerator * f.GetNumerator(), _denominator * f.GetDenominator()));
 }