static void Main(string[] args) { Dathuc a = new Dathuc(); Dathuc b = new Dathuc(); Dathuc c = new Dathuc(); a.Nhap(); a.XuatDaThuc(); Console.WriteLine("---------------------------------"); b.Nhap(); b.XuatDaThuc(); Console.WriteLine("---------------------------------"); Console.WriteLine("Cong hai da thuc :"); c.CongDaThuc(a, b).XuatDaThuc(); //c = a + b; //c.XuatDaThuc(); Console.WriteLine("---------------------------------"); Console.WriteLine("Tru hai da thuc :"); c.TruDaThuc(a, b).XuatDaThuc(); b.XuatDaThuc(); //c = a - b; //c.XuatDaThuc(); Console.WriteLine("---------------------------------"); Console.WriteLine("Dao ham da thuc 1 :"); a.DaoHam().XuatDaThuc(); Console.ReadLine(); }
public static Dathuc operator -(Dathuc dt1, Dathuc dt2) { Dathuc dt_tong = new Dathuc(); for (int i = 0; i < dt1.Sopt; i++) { dt_tong.ThemSohang(dt1.DT[i].Hs, dt1.DT[i].Mu); } for (int i = 0; i < dt2.Sopt; i++) { dt_tong.ThemSohang(dt2.DT[i].Hs, dt2.DT[i].Mu); } dt_tong.SapGiamDanTheoSoMu(); for (int i = 0; i < dt_tong.Sopt - 1; i++) { if (dt_tong.DT[i].Mu == dt_tong.DT[i + 1].Mu) { dt_tong.DT[i].Hs -= dt_tong.DT[i + 1].Hs; for (int j = i + 1; j < dt_tong.Sopt - 1; j++) { dt_tong.DT[j] = dt_tong.DT[j + 1]; } dt_tong.Sopt--; i--; } } return(dt_tong); }
public Dathuc DaoHam() { Dathuc c = new Dathuc(bac - 1); for (int i = c.bac; i >= 0; i--) { c.a[i] = a[i + 1] * (i + 1); } return(c); }
static void Main(string[] args) { Dathuc a = new Dathuc(); Dathuc c = new Dathuc(); Dathuc b = new Dathuc(); a.NhapDaThuc(); //a.RutGon(a).XuatDathuc(); a.Sapxep(); a.RutGon(); a.XuatDathuc(); Console.ReadLine(); }
public static Dathuc operator +(Dathuc dt1, Dathuc dt2) { Dathuc dt_tong = new Dathuc(); for (int i = 0; i < dt1.Sopt; i++) { dt_tong.ThemSohang(dt1.DT[i].Hs, dt1.DT[i].Mu); } for (int i = 0; i < dt2.Sopt; i++) { dt_tong.ThemSohang(dt2.DT[i].Hs, dt2.DT[i].Mu); } dt_tong.SapGiamDanTheoSoMu(); dt_tong.RutGonDaThuc(); return(dt_tong); }
public Dathuc CongDaThuc(Dathuc a, Dathuc b) { Dathuc c; if (a.bac < b.bac) { c = b; for (int i = 0; i <= a.bac; i++) { c.a[i] = a.a[i] + b.a[i]; } } else { c = a; for (int i = 0; i <= b.bac; i++) { c.a[i] = a.a[i] + b.a[i]; } } return(c); }
static void Main(string[] args) { Dathuc T1 = new Dathuc(); T1.NhapDaThuc(); T1.XuatDaThuc(); Dathuc T2 = new Dathuc(); T2.NhapDaThuc(); T2.XuatDaThuc(); Console.WriteLine("T1 + T2 = "); Dathuc Tong = T1 + T2; Tong.XuatDaThuc(); Console.WriteLine("T1 - T2 = "); Dathuc Hieu = T1 - T2; Hieu.XuatDaThuc(); Console.ReadLine(); }