Beispiel #1
0
        static void Main(string[] args)
        {
            var dathuc_1 = new DaThuc(3);

            dathuc_1.NhapDaThuc();
            dathuc_1.XuatDaThuc();

            var dathuc_2 = new DaThuc(3);

            dathuc_2.NhapDaThuc();
            dathuc_2.XuatDaThuc();

            Console.WriteLine();

            Console.WriteLine("Da thuc 1 + Da thuc 2 = ");
            var dathuc_tong = dathuc_1 + dathuc_2;

            dathuc_tong.XuatDaThuc();
            var tong_2 = dathuc_1.Cong(dathuc_2);

            tong_2.XuatDaThuc();

            Console.WriteLine();
            Console.WriteLine("Da thuc 1 - Da thuc 2 = ");
            var dathuc_hieu = dathuc_1 - dathuc_2;

            dathuc_hieu.XuatDaThuc();
            var hieu_2 = dathuc_1.Tru(dathuc_2);

            hieu_2.XuatDaThuc();

            Console.ReadLine();
        }
Beispiel #2
0
        public DaThuc Tru(DaThuc dt2)
        {
            int bacCaoHon  = this.n > dt2.n ? this.n : dt2.n;
            int bacThapHon = this.n < dt2.n ? this.n : dt2.n;

            DaThuc dt_tong = new DaThuc(bacCaoHon);

            for (int i = 0; i <= bacThapHon; i++)
            {
                dt_tong.array[i] = this.array[i] - dt2.array[i];
            }

            if (this.n == bacThapHon)
            {
                for (int i = bacThapHon + 1; i <= dt2.n; i++)
                {
                    dt_tong.array[i] = dt2.array[i];
                }
            }
            else
            {
                for (int i = bacThapHon + 1; i <= this.n; i++)
                {
                    dt_tong.array[i] = this.array[i];
                }
            }

            return(dt_tong);
        }
Beispiel #3
0
        public static DaThuc operator -(DaThuc dt1, DaThuc dt2)
        {
            int bacCaoHon  = dt1.n > dt2.n ? dt1.n : dt2.n;
            int bacThapHon = dt1.n < dt2.n ? dt1.n : dt2.n;

            DaThuc dt_tong = new DaThuc(bacCaoHon);

            for (int i = 0; i <= bacThapHon; i++)
            {
                dt_tong.array[i] = dt1.array[i] - dt2.array[i];
            }

            if (dt1.n == bacThapHon)
            {
                for (int i = bacThapHon + 1; i <= dt2.n; i++)
                {
                    dt_tong.array[i] = dt2.array[i];
                }
            }
            else
            {
                for (int i = bacThapHon + 1; i <= dt1.n; i++)
                {
                    dt_tong.array[i] = dt1.array[i];
                }
            }

            return(dt_tong);
        }