public static RationalNumber operator /(RationalNumber number1, int number2) { RationalNumber temp = new RationalNumber(number2, 1); int NOD = Math.Abs(AppliedMath.NOD(number1.Numerator * temp.Denominator, number1.Denominator * temp.Numerator)); return(new RationalNumber(number1.Numerator * temp.Denominator / NOD, number1.Denominator * temp.Numerator / NOD)); }
public static RationalNumber operator -(RationalNumber number1, RationalNumber number2) { int NewDenominator = AppliedMath.NOK(number1._Denominator, number2._Denominator); int NOD = Math.Abs(AppliedMath.NOD(number1.Numerator * NewDenominator / number1.Denominator - number2.Numerator * NewDenominator / number2.Denominator, NewDenominator)); return(new RationalNumber((number1.Numerator * NewDenominator / number1.Denominator - number2.Numerator * NewDenominator / number2.Denominator) / NOD, NewDenominator / NOD)); }
public string ToString(string Format) { if (Format == string.Empty) { return(ToString()); } else if (Format == "with fractions") { string temp = string.Empty; int NOD = Math.Abs(AppliedMath.NOD(Numerator, Denominator)); for (int i = 0; i < (Numerator / NOD).ToString().Length; i++) { temp = string.Concat(temp, '-'); } if (Numerator >= 0) { return($"{Numerator / NOD}\n{temp}\n{Denominator / NOD}"); } else { temp = temp.Remove(1, 1); return($"{Numerator / NOD}\n {temp}\n {Denominator / NOD}"); } } else if (Format == "mixed fraction") { if (Math.Abs(Numerator) < Denominator) { return(ToString()); } else if (Numerator % Denominator == 0) { return((Numerator / Denominator).ToString()); } else { if (Numerator == 0) { return("0"); } else { int NOD = Math.Abs(AppliedMath.NOD(Numerator - Denominator * (Numerator / Denominator), Denominator)); return($"{Numerator / Denominator}+({(Numerator - Denominator * (Numerator / Denominator)) / NOD}/{Denominator / NOD})"); } } } else if (Format == "reduced fraction") { int NOD = Math.Abs(AppliedMath.NOD(Numerator, Denominator)); return($"{Numerator / NOD}/{Denominator / NOD}"); } return(string.Empty); }
public static RationalNumber operator /(RationalNumber number1, RationalNumber number2) { int NOD = Math.Abs(AppliedMath.NOD(number1.Numerator * number2.Denominator, number1.Denominator * number2.Numerator)); return(new RationalNumber(number1.Numerator * number2.Denominator / NOD, number1.Denominator * number2.Numerator / NOD)); }