Beispiel #1
0
        static void Main()
        {
            Console.OutputEncoding = Encoding.UTF8;
            Console.WriteLine("Nhập thông tin vecto thứ 1 :");
            Vecto t1 = new Vecto(5); t1.Nhap();

            Console.WriteLine("Nhập thông tin cho vecto thứ 2 :");
            Vecto t2 = new Vecto(5); t2.Nhap();

            Console.WriteLine("Tổng hai vecto:");
            Vecto t3 = t1.Tong(t2);

            Console.WriteLine("Hiệu hai vecto:");
            Vecto t4 = t1.Hieu(t2);

            if (t3 == null)
            {
                if (t4 == null)
                {
                    Console.WriteLine("ERRORS!");
                }
                else
                {
                    Console.WriteLine("Tổng hai vecto:");
                    t3.Hien();
                    Console.WriteLine("Hiệu hai vecto:");
                    t4.Hien();
                }
            }
            Console.ReadKey();
        }
Beispiel #2
0
 public Vecto Hieu(Vecto t2)
 {
     // tính hiệu 2 vecto.
     if (this.n == t2.n)
     {
         Vecto t = new Vecto(this.n);
         for (int i = 0; i < n; ++i)
         {
             t.v[i] = this.v[i] - t2.v[i];
         }
         return(t);
     }
     else
     {
         return(null);
     }
 }
Beispiel #3
0
 public Vecto Tong(Vecto t2)
 {
     // tính tổng 2 vecto.
     if (this.n == t2.n)
     {
         Vecto t = new Vecto(this.n);
         for (int i = 0; i < n; ++i)
         {
             t.v[i] = this.v[i] + t2.v[i];
         }
         return(t);
     }
     else
     {
         return(null);
     }
 }