Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.Write("nhap so hang cua ma tran 1 ");
            int soHangMT1 = int.Parse(Console.ReadLine());

            Console.Write("nhap so cot cua  ma tra 1 ");
            int soCotMT1 = int.Parse(Console.ReadLine());
            var a        = new MaTrix1(soHangMT1, soCotMT1);

            a.Nhap();
            Console.Write("nhap so hang cua ma tran 2 ");
            int soHangMT2 = int.Parse(Console.ReadLine());

            Console.Write("nhap so cot cua  ma tra 1 ");
            int soCotMt2 = int.Parse(Console.ReadLine());
            var b        = new MaTrix1(soHangMT2, soCotMt2);

            b.Nhap();
            if (soCotMT1 != soCotMt2 || soHangMT1 != soHangMT2)
            {
                throw new Exception("loi");
            }

            var x = a.Add(b);
            var y = a.Tru(b);

            x.Xuat();

            Console.ReadKey();
        }
Ejemplo n.º 2
0
 public bool KiemTra(MaTrix1 other)
 {
     if (this.Hang != other.Hang || this.Cot != other.Cot)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 3
0
 public MaTrix1 Chia(MaTrix1 other)
 {
     int[,] a = new int[Hang, Cot];
     for (int i = 0; i < soHang; i++)
     {
         for (int j = 0; j < soCot; j++)
         {
             a[i, j] = this.Get(i, j) / other.Get(i, j);
         }
     }
     return(new MaTrix1(a));
 }
Ejemplo n.º 4
0
        public MaTrix1 Add(MaTrix1 other)
        {
            if (!this.KiemTra(other))
            {
                throw new Exception("Loi khong cong dc");
            }

            int[,] result = new int[Hang, Cot];

            for (int i = 0; i < soHang; i++)
            {
                for (int j = 0; j < soCot; j++)
                {
                    result[i, j] = this.Get(i, j) + other.Get(i, j);
                }
            }
            return(new MaTrix1(result));
        }