using System;
using System.Windows.Forms;

namespace _5_8
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int ra = 2, ca = 3;
            int rb = 3, cb = 4;
            int[,] a = { { 1, 2, 3 }, { 4, 5, 6 } };
            int[,] b = { { 7, 8, 9, 1 }, { 2, 3, 4, 5 }, { 6, 7, 8, 9 } };
            int[,] c = new int[ra, cb];

            if (ca != rb)
                MessageBox.Show("ضرب دو ماتریس امکان‌پذیر نیست.");
            else
            {
                for (int i = 0; i < ra; i++)
                    for (int j = 0; j < cb; j++)
                        for (int k = 0; k < ca; k++)
                            c[i, j] = c[i, j] + a[i, k] * b[k, j];
            }

            for (int i = 0; i < ra; i++)
            {
                for (int j = 0; j < cb; j++)
                    textBox1.AppendText(c[i, j].ToString() + "\t");
                textBox1.AppendText(System.Environment.NewLine);
            }
        }
    }
}