static void Main3() { Matran a = new Matran(2, 3); Console.WriteLine("Nhap ma tran thu 1:"); a.Nhap(); Matran b = new Matran(a); Console.WriteLine("Nhap ma tran thu 2:"); b.Nhap(); Console.WriteLine("Ma tran thu 1"); a.print(); Console.WriteLine("Ma tran thu 2"); b.print(); Matran c = a.Tong(b); if (c == null) { Console.WriteLine(" Hai ma tran co kich thuoc khac nhau"); } else { Console.WriteLine("Ma tran tong"); c.print(); } Matran d = a.Hieu(b); if (d == null) { Console.WriteLine(" Hai ma tran co kich thuoc khac nhau"); } else { Console.WriteLine("Ma tran hieu"); d.print(); } Console.ReadKey(); }
public Matran(Matran t2) { this.sh = t2.sh; this.sc = t2.sc; this.a = new int[sh, sc]; for (int i = 0; i < sh; i++) { for (int j = 0; j < sc; j++) { this.a[i, j] = t2.a[i, j]; } } }
public Matran Hieu(Matran t2) { if (this.sh == t2.sh && this.sc == t2.sc) { Matran t1 = new Matran(this.sh, this.sc); for (int i = 0; i < sh; i++) { for (int j = 0; j < sc; j++) { t1.a[i, j] = this.a[i, j] - t2.a[i, j]; } } return(t1); } else { return(null); } }
public Matran Tong(Matran t2) { if (this.sh == t2.sh && this.sc == t2.sc) { Matran t = new Matran(this.sh, this.sc); for (int i = 0; i < sh; i++) { for (int j = 0; j < sc; j++) { t.a[i, j] = this.a[i, j] + t2.a[i, j]; } } return(t); } else { return(null); } }