Exemplo n.º 1
0
        public static Matran operator -(Matran a, Matran b)
        {
            Matran kq = new Matran(a.soDong, a.soCot);

            for (int i = 0; i < kq.soDong; i++)
            {
                for (int j = 0; j < kq.SoCot; j++)
                {
                    kq.a[i, j] = a.a[i, j] - b.a[i, j];
                }
            }
            return(kq);
        }
Exemplo n.º 2
0
        public static Matran operator *(Matran a, Matran b)
        {
            Matran kq = new Matran(a.soDong, b.soCot);

            for (int i = 0; i < kq.soDong; i++)
            {
                for (int j = 0; j < kq.SoCot; j++)
                {
                    int sum = 0;
                    for (int r = 0; r < a.soCot; r++)
                    {
                        sum = sum + (a.a[i, r] * b.a[r, j]);
                    }
                    kq.a[i, j] = sum;
                }
            }
            return(kq);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Nhap ma tran A: ");
            Matran matran1 = new Matran();

            matran1.Nhap();
            matran1.Xuat();

            Console.WriteLine("Nhap ma tran B: ");
            Matran matran2 = new Matran();

            matran2.Nhap();
            matran2.Xuat();

            Matran matran3 = new Matran();
            int    x;

            Console.WriteLine("\nNhap 1 tinh A + B\nNhap 2 tinh A - B\nNhap 3 tinh A * B");
            x = int.Parse(Console.ReadLine());
            if (x == 1)
            {
                matran3 = matran1 + matran2;
            }
            else
            {
                if (x == 2)
                {
                    matran3 = matran1 - matran2;
                }
                else
                {
                    matran3 = matran1 * matran2;
                }
            }
            matran3.Xuat();
        }