예제 #1
0
 public Rational Multiply(Rational num2)
 {
     int numer = numerator * num2.GetNumerator();
     int denom = denominator * num2.GetDenominator();
     Rational result = new Rational(numer, denom);
     return result;
 }
예제 #2
0
        public Rational Divide(Rational num2)
        {
            int numer = num2.GetDenominator();
            int denom = num2.GetNumerator();

            Rational r = new Rational(numer, denom);
            Rational result = Multiply(r);
            return result;
        }
예제 #3
0
 public Rational Add(Rational num2)
 {
     int commonDenom = denominator * num2.GetDenominator();
     int numer1 = numerator * num2.GetDenominator();
     int numer2 = num2.GetNumerator() * denominator;
     int sum = numer1 + numer2;
     Rational result = new Rational(sum, commonDenom);
     return result;
 }
예제 #4
0
 public Rational Subtract(Rational num2)
 {
     int commonDenom = denominator * num2.GetDenominator();
     int numer1 = numerator * num2.GetDenominator();
     int numer2 = num2.GetNumerator() * denominator;
     int difference = numer1 - numer2;
     Rational result = new Rational(difference, commonDenom);
     return result;
 }