public static Fraction operator -(Fraction fraction1, Fraction fraction2) { Fraction result = new Fraction(); result.numerator = fraction1.numerator * fraction2.denominator - fraction2.numerator * fraction1.denominator; result.denominator = fraction1.denominator * fraction2.denominator; return result; }
public static Fraction operator -(Fraction firstFrac, Fraction secFrac) { long numerator = firstFrac.Numerator * secFrac.Denominator - secFrac.Numerator * firstFrac.Denominator; long denominator = firstFrac.Denominator * secFrac.Denominator; Fraction result = new Fraction(numerator, denominator); return result; }
static void Main(string[] args) { Fraction fraction1 = new Fraction(22, 7); Fraction fraction2 = new Fraction(40, 4); Fraction result = fraction1 + fraction2; Console.WriteLine(result.Numerator); Console.WriteLine(result.Denominator); Console.WriteLine(result); }