Пример #1
0
        public static Fraction operator /(Fraction fr1, long n) //необходимо проверить
        {
            long     l;
            Fraction fr2 = new Fraction(n, 1);
            Fraction i   = new Fraction(fr2.numerator, fr2.denominator);
            Fraction j   = new Fraction(fr1.numerator, fr1.denominator);

            if (fr2.numerator < 0)
            {
                l             = -i.numerator;
                i.numerator   = i.denominator;
                i.denominator = l;
                j.numerator   = -j.numerator;
            }
            else if (fr2.numerator == 0)
            {
                //выбросить исключение
            }
            else
            {
                l             = i.numerator;
                i.numerator   = i.denominator;
                i.denominator = l;
            }
            l           = j.numerator;
            j.numerator = i.numerator;
            i.numerator = l;
            j.Normalize();
            i.Normalize();
            return(new Fraction(j.numerator * i.numerator, i.denominator * j.denominator));
        }
Пример #2
0
        public static Fraction operator*(Fraction fr1, Fraction fr2) //перегрузка оператора умножения
        {
            Fraction i = new Fraction(fr1.numerator, fr1.denominator);;
            Fraction j = new Fraction(fr2.numerator, fr2.denominator);;
            long     l = j.numerator;

            j.numerator = i.numerator;
            i.numerator = l;
            j.Normalize();
            i.Normalize();
            return(new Fraction(j.numerator * i.numerator, j.denominator * i.denominator));
        }