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(); }
public bool KiemTra(MaTrix1 other) { if (this.Hang != other.Hang || this.Cot != other.Cot) { return(false); } return(true); }
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)); }
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)); }