2010年10月29日 星期五

數字遊戲完成板

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        System.Windows.Forms.Button[] Buttons;
        System.Windows.Forms.TextBox[] TextBoxs;
        public Form1()
        {
            InitializeComponent();
       
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            Buttons = new System.Windows.Forms.Button[9];
            TextBoxs = new System.Windows.Forms.TextBox[9];
         
            for (int i = 0; i < 9; ++i)
            {
                Buttons[i] = new Button();
                Buttons[i].Click += new System.EventHandler(Buttons_Click);
                this.Controls.Add(Buttons[i]);
                if (i <= 2)
                    Buttons[i].Location = new System.Drawing.Point(10 + i * 120, 110);
                else if (i > 2 && i <= 5)
                    Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 120, 140);
                else if (i > 5 && i <= 9)
                    Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 120, 170);
            }
            for (int i = 0; i < 9; ++i)
            {
                TextBoxs[i] = new TextBox();
                this.Controls.Add(TextBoxs[i]);
                if (i <= 2)
                    TextBoxs[i].Location = new System.Drawing.Point(10 + i * 110, 10);
                else if (i > 2 && i <= 5)
                    TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 3) * 110, 40);
                else if (i > 5 && i <= 9)
                    TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 6) * 110, 70);
            }

            TextBoxs[0].Text = "7";
            TextBoxs[1].Text = "2";
            TextBoxs[2].Text = "4";
            TextBoxs[3].Text = "5";
            TextBoxs[4].Text = "0";
            TextBoxs[5].Text = "6";
            TextBoxs[6].Text = "8";
            TextBoxs[7].Text = "3";
            TextBoxs[8].Text = "1";

        }
        public void Buttons_Click(object sender, EventArgs e)
        {
            // System.Windows.Forms.MessageBox.Show("You have clicked button " +
            //   ((System.Windows.Forms.Button)sender).Tag.ToString());
            int bno=0;
            String tnum = sender.ToString();
            int tlen = tnum.Length;
            String no = tnum.Substring(tlen - 1);
            for (int i = 0; i < 9; i++)
            {
                if (Buttons[i].Text == no)
                    bno = i;
            }
            switch (bno)
            {
                case 0:
                    if (Buttons[1].Text == "0")
                    {
                        String temp;
                        temp = Buttons[1].Text;
                        Buttons[1].Text = Buttons[0].Text;
                        Buttons[0].Text = temp;
                    }
                    if (Buttons[3].Text == "0")
                    {
                        String temp;
                        temp = Buttons[3].Text;
                        Buttons[3].Text = Buttons[0].Text;
                        Buttons[0].Text = temp;
                    }
                  
                    break;
                case 1:
                    if (Buttons[4].Text == "0")
                    {
                        String temp;
                        temp = Buttons[4].Text;
                        Buttons[4].Text = Buttons[1].Text;
                        Buttons[1].Text = temp;
                    }
                    if (Buttons[0].Text == "0")
                    {
                        String temp;
                        temp = Buttons[0].Text;
                        Buttons[0].Text = Buttons[1].Text;
                        Buttons[1].Text = temp;
                    }
                    if (Buttons[2].Text == "0")
                    {
                        String temp;
                        temp = Buttons[2].Text;
                        Buttons[2].Text = Buttons[1].Text;
                        Buttons[1].Text = temp;
                    }
                  
                   
                    break;
                case 2:
                    if (Buttons[1].Text == "0")
                    {
                        String temp;
                        temp = Buttons[1].Text;
                        Buttons[1].Text = Buttons[2].Text;
                        Buttons[2].Text = temp;
                    }
                    if (Buttons[5].Text == "0")
                    {
                        String temp;
                        temp = Buttons[5].Text;
                        Buttons[5].Text = Buttons[2].Text;
                        Buttons[2].Text = temp;
                    }
                  
                    break;
                case 3:
                    if (Buttons[4].Text == "0")
                    {
                        String temp;
                        temp = Buttons[4].Text;
                        Buttons[4].Text = Buttons[3].Text;
                        Buttons[3].Text = temp;
                    }
                    if (Buttons[0].Text == "0")
                    {
                        String temp;
                        temp = Buttons[0].Text;
                        Buttons[0].Text = Buttons[3].Text;
                        Buttons[3].Text = temp;
                    }
                    if (Buttons[6].Text == "0")
                    {
                        String temp;
                        temp = Buttons[6].Text;
                        Buttons[6].Text = Buttons[6].Text;
                        Buttons[3].Text = temp;
                    }
                  
                    break;
                case 4:
                    if (Buttons[1].Text == "0")
                    {
                        String temp;
                        temp = Buttons[1].Text;
                        Buttons[1].Text = Buttons[4].Text;
                        Buttons[4].Text = temp;
                    }
                    if (Buttons[3].Text == "0")
                    {
                        String temp;
                        temp = Buttons[3].Text;
                        Buttons[3].Text = Buttons[4].Text;
                        Buttons[4].Text = temp;
                    }
                    if (Buttons[5].Text == "0")
                    {
                        String temp;
                        temp = Buttons[5].Text;
                        Buttons[5].Text = Buttons[4].Text;
                        Buttons[4].Text = temp;
                    }
                    if (Buttons[7].Text == "0")
                    {
                        String temp;
                        temp = Buttons[7].Text;
                        Buttons[7].Text = Buttons[4].Text;
                        Buttons[4].Text = temp;
                    }
                    break;
                case 5:
                    if (Buttons[4].Text == "0")
                    {
                        String temp;
                        temp = Buttons[4].Text;
                        Buttons[4].Text = Buttons[5].Text;
                        Buttons[5].Text = temp;
                    }
                    if (Buttons[2].Text == "0")
                    {
                        String temp;
                        temp = Buttons[2].Text;
                        Buttons[2].Text = Buttons[5].Text;
                        Buttons[5].Text = temp;
                    }
                    if (Buttons[8].Text == "0")
                    {
                        String temp;
                        temp = Buttons[8].Text;
                        Buttons[8].Text = Buttons[5].Text;
                        Buttons[5].Text = temp;
                    }
                  
                    break;
                case 6:
                    if (Buttons[3].Text == "0")
                    {
                        String temp;
                        temp = Buttons[3].Text;
                        Buttons[3].Text = Buttons[6].Text;
                        Buttons[6].Text = temp;
                    }
                    if (Buttons[7].Text == "0")
                    {
                        String temp;
                        temp = Buttons[7].Text;
                        Buttons[7].Text = Buttons[6].Text;
                        Buttons[6].Text = temp;
                    }
                    break;
                case 7:
                    if (Buttons[4].Text == "0")
                    {
                        String temp;
                        temp = Buttons[4].Text;
                        Buttons[4].Text = Buttons[7].Text;
                        Buttons[7].Text = temp;
                    }
                    if (Buttons[6].Text == "0")
                    {
                        String temp;
                        temp = Buttons[6].Text;
                        Buttons[6].Text = Buttons[7].Text;
                        Buttons[7].Text = temp;
                    }
                    if (Buttons[8].Text == "0")
                    {
                        String temp;
                        temp = Buttons[8].Text;
                        Buttons[8].Text = Buttons[7].Text;
                        Buttons[7].Text = temp;
                    }
                  
                    break;
                case 8:
                    if (Buttons[7].Text == "0")
                    {
                        String temp;
                        temp = Buttons[7].Text;
                        Buttons[7].Text = Buttons[8].Text;
                        Buttons[8].Text = temp;
                    } if (Buttons[5].Text == "0")
                    {
                        String temp;
                        temp = Buttons[5].Text;
                        Buttons[5].Text = Buttons[8].Text;
                        Buttons[8].Text = temp;
                    }
                    break;

            }
        }
        private void button1_Click(object sender, EventArgs e)
   
        {
            for (int i = 0; i < 9; i++)
            {
                Buttons[i].Text = Convert.ToString(TextBoxs[i].Text);
            }
        }

       
    }
}

2010年10月22日 星期五

數字遊戲(未完成版)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        System.Windows.Forms.Button[] Buttons;
        System.Windows.Forms.TextBox[] TextBoxs;
        public Form1()
        {
            InitializeComponent();
        }
      
        private void Form1_Load(object sender, EventArgs e)
        {
            Buttons = new System.Windows.Forms.Button[9];
            TextBoxs = new System.Windows.Forms.TextBox[9];
          
            for (int i = 0; i <9; ++i)
            {
                Buttons[i] = new Button();
                Buttons[i].Click += new System.EventHandler(Buttons_Click);
                this.Controls.Add(Buttons[i]);
                if (i <= 2)
                    Buttons[i].Location = new System.Drawing.Point(10 + i * 120, 110);
                else if (i > 2 && i <= 5)
                    Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 120, 140);
                else if (i > 5 && i <= 9)
                    Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 120, 170);
            }

            for (int i = 0; i < 9; ++i)
            {
                TextBoxs[i] = new TextBox();
                this.Controls.Add(TextBoxs[i]);
                if (i <= 2)
                    TextBoxs[i].Location = new System.Drawing.Point(10 + i * 110, 10);
                else if (i > 2 && i <= 5)
                    TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 3) * 110, 40);
                else if (i > 5 && i <= 9)
                    TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 6) * 110, 70);
            }


            TextBoxs[0].Text = "7";
            TextBoxs[1].Text = "2";
            TextBoxs[2].Text = "4";
            TextBoxs[3].Text = "5";
            TextBoxs[4].Text = "0";
            TextBoxs[5].Text = "6";
            TextBoxs[6].Text = "8";
            TextBoxs[7].Text = "3";
            TextBoxs[8].Text = "1";
           

          
        }
        public void Buttons_Click(object sender, EventArgs e)
        {
            // System.Windows.Forms.MessageBox.Show("You have clicked button " +
            //   ((System.Windows.Forms.Button)sender).Tag.ToString());
            MessageBox.Show("button_click"+sender.ToString());
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 9; i++)
            {
                Buttons[i].Text = Convert.ToString(TextBoxs[i].Text);
            }
        }
    }
}

複合式4X4矩陣(內建單位矩陣X單位矩陣)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        System.Windows.Forms.TextBox[] TextBoxes;
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            TextBoxes = new System.Windows.Forms.TextBox[17];
            for (int i = 1; i <= 16; ++i)
            {
                TextBoxes[i] = new TextBox();
                this.Controls.Add(TextBoxes[i]);
                if (i <= 4)
                    TextBoxes[i].Location = new System.Drawing.Point(12 + (i - 1) * 106, 12);
                else if (i > 4 && i <= 8)
                    TextBoxes[i].Location = new System.Drawing.Point(12 + (i - 5) * 106, 40);
                else if (i > 8 && i <= 12)
                    TextBoxes[i].Location = new System.Drawing.Point(12 + (i - 9) * 106, 68);
                else if (i > 12 && i <= 16)
                    TextBoxes[i].Location = new System.Drawing.Point(12 + (i - 13) * 106, 96);
                //產生出16個TextBox,並排列整齊成為4x4的空格方陣
            }
            //在此環境下製作的TextBox會直接出現在form上
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int[,] a = new int[5, 5];
            int[,] b = new int[5, 5];
            int[,] c = new int[5, 5];
       
            int m = 5, n = 5;
  
            a[1, 1] = int.Parse(textBox1.Text);
            a[1, 2] = int.Parse(textBox5.Text);
            a[1, 3] = int.Parse(textBox9.Text);
            a[1, 4] = int.Parse(textBox13.Text);
            a[2, 1] = int.Parse(textBox2.Text);
            a[2, 2] = int.Parse(textBox6.Text);
            a[2, 3] = int.Parse(textBox10.Text);
            a[2, 4] = int.Parse(textBox14.Text);
            a[3, 1] = int.Parse(textBox3.Text);
            a[3, 2] = int.Parse(textBox7.Text);
            a[3, 3] = int.Parse(textBox11.Text);
            a[3, 4] = int.Parse(textBox15.Text);
            a[4, 1] = int.Parse(textBox4.Text);
            a[4, 2] = int.Parse(textBox8.Text);
            a[4, 3] = int.Parse(textBox12.Text);
            a[4, 4] = int.Parse(textBox16.Text);
            b[1, 1] = int.Parse(textBox17.Text);
            b[1, 2] = int.Parse(textBox21.Text);
            b[1, 3] = int.Parse(textBox25.Text);
            b[1, 4] = int.Parse(textBox29.Text);
            b[2, 1] = int.Parse(textBox18.Text);
            b[2, 2] = int.Parse(textBox22.Text);
            b[2, 3] = int.Parse(textBox26.Text);
            b[2, 4] = int.Parse(textBox30.Text);
            b[3, 1] = int.Parse(textBox19.Text);
            b[3, 2] = int.Parse(textBox23.Text);
            b[3, 3] = int.Parse(textBox27.Text);
            b[3, 4] = int.Parse(textBox31.Text);
            b[4, 1] = int.Parse(textBox20.Text);
            b[4, 2] = int.Parse(textBox24.Text);
            b[4, 3] = int.Parse(textBox28.Text);
            b[4, 4] = int.Parse(textBox32.Text);
           
            for (int i = 1; i < m; i++)
            {
                for (int j = 1; j < n; j++)
                {
                    for (int k = 1; k < m; k++)
                    {
                        c[i, j] = c[i, j] + a[i, k] * b[k, j];
                    }
                }
            }
            for (int i = 1; i <= 4; i++)
            {
                TextBoxes[i].Text = Convert.ToString(c[i, 1]);
                TextBoxes[i + 4].Text = Convert.ToString(c[i, 2]);
                TextBoxes[i + 8].Text = Convert.ToString(c[i, 3]);
                TextBoxes[i + 12].Text = Convert.ToString(c[i, 4]);
                //使用for迴圈呈現答案於16個Textbox之中
            }

        }
        private void textBox23_TextChanged(object sender, EventArgs e)
        {
        }
        private void button2_Click(object sender, EventArgs e)
        {
            int[,] a = new int[5, 5];
            int[,] b = new int[5, 5];
            int[,] c = new int[5, 5];
            int m = 5, n = 5;

            textBox1.Text = "1";
            textBox2.Text = "0";
            textBox3.Text = "0";
            textBox4.Text = "0";

            textBox5.Text = "0";
            textBox6.Text = "1";
            textBox7.Text = "0";
            textBox8.Text = "0";
            textBox9.Text = "0";
            textBox10.Text = "0";
            textBox11.Text = "1";
            textBox12.Text = "0";
            textBox13.Text = "0";
            textBox14.Text = "0";
            textBox15.Text = "0";
            textBox16.Text = "1";

            textBox17.Text = "1";
            textBox18.Text = "0";
            textBox19.Text = "0";
            textBox20.Text = "0";

            textBox21.Text = "0";
            textBox22.Text = "1";
            textBox23.Text = "0";
            textBox24.Text = "0";
            textBox25.Text = "0";
            textBox26.Text = "0";
            textBox27.Text = "1";
            textBox28.Text = "0";
            textBox29.Text = "0";
            textBox30.Text = "0";
            textBox31.Text = "0";
            textBox32.Text = "1";
            a[1, 1] = 1;
            a[1, 2] = 0;
            a[1, 3] = 0;
            a[1, 4] = 0;
            a[2, 1] = 0;
            a[2, 2] = 1;
            a[2, 3] = 0;
            a[2, 4] = 0;
            a[3, 1] = 0;
            a[3, 2] = 0;
            a[3, 3] = 1;
            a[3, 4] = 0;
            a[4, 1] = 0;
            a[4, 2] = 0;
            a[4, 3] = 0;
            a[4, 4] = 1;
            b[1, 1] = 1;
            b[1, 2] = 0;
            b[1, 3] = 0;
            b[1, 4] = 0;
            b[2, 1] = 0;
            b[2, 2] = 1;
            b[2, 3] = 0;
            b[2, 4] = 0;
            b[3, 1] = 0;
            b[3, 2] = 0;
            b[3, 3] = 1;
            b[3, 4] = 0;
            b[4, 1] = 0;
            b[4, 2] = 0;
            b[4, 3] = 0;
            b[4, 4] = 1;
           
          
            for (int i = 1; i < m; i++)
            {
                for (int j = 1; j < n; j++)
                {
                    for (int k = 1; k < m; k++)
                    {
                        c[i, j] = c[i, j] + a[i, k] * b[k, j];
                    }
                }
            }
            for (int i = 1; i <= 4; i++)
            {
                TextBoxes[i].Text = Convert.ToString(c[i, 1]);
                TextBoxes[i + 4].Text = Convert.ToString(c[i, 2]);
                TextBoxes[i + 8].Text = Convert.ToString(c[i, 3]);
                TextBoxes[i + 12].Text = Convert.ToString(c[i, 4]);
                //使用for迴圈呈現答案於16個Textbox之中
            }
        }
        }
    }

2010年10月15日 星期五

4x4矩陣完成版(Use for迴圈and物件產生)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        System.Windows.Forms.TextBox[] TextBoxes;
        //先宣告TextBox的矩陣

        private void Form1_Load(object sender, EventArgs e)
        {
            TextBoxes = new System.Windows.Forms.TextBox[17];

            for (int i = 1; i <= 16; ++i)
            {
                TextBoxes[i] = new TextBox();
                this.Controls.Add(TextBoxes[i]);
                if (i <= 4)
                    TextBoxes[i].Location = new System.Drawing.Point(12 + (i - 1) * 106, 12);
                     
          
                
                else if (i > 4 && i <= 8)
                    TextBoxes[i].Location = new System.Drawing.Point(12 + (i - 5) * 106, 40);
                else if (i > 8 && i <= 12)
                    TextBoxes[i].Location = new System.Drawing.Point(12 + (i - 9) * 106, 68);
                else if (i > 12 && i <= 16)
                    TextBoxes[i].Location = new System.Drawing.Point(12 + (i - 13) * 106, 96);
                //產生出16個TextBox,並排列整齊成為4x4的空格方陣
            }
                //在此環境下製作的TextBox會直接出現在form上
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int[,] a = new int[5, 5];
            int[,] b = new int[5, 5];
            int[,] c = new int[5, 5];
            int m = 5, n = 5;
            a[1, 1] = 1;
            a[1, 2] = 0;
            a[1, 3] = 0;
            a[1, 4] = 0;
            a[2, 1] = 0;
            a[2, 2] = 1;
            a[2, 3] = 0;
            a[2, 4] = 0;
            a[3, 1] = 0;
            a[3, 2] = 0;
            a[3, 3] = 1;
            a[3, 4] = 0;
            a[4, 1] = 0;
            a[4, 2] = 0;
            a[4, 3] = 0;
            a[4, 4] = 1;
            b[1, 1] = 1;
            b[1, 2] = 0;
            b[1, 3] = 0;
            b[1, 4] = 0;
            b[2, 1] = 0;
            b[2, 2] = 1;
            b[2, 3] = 0;
            b[2, 4] = 0;
            b[3, 1] = 0;
            b[3, 2] = 0;
            b[3, 3] = 1;
            b[3, 4] = 0;
            b[4, 1] = 0;
            b[4, 2] = 0;
            b[4, 3] = 0;
            b[4, 4] = 4;
         
            for (int i = 1; i < m; i++)
            {
                for (int j = 1; j < n; j++)
                {
                    for (int k = 1; k < m; k++)
                    {
                        c[i, j] = c[i, j] + a[i, k] * b[k, j];
                    }
                
                }
            }
            //使用for迴圈計算矩陣乘法

            for (int i=1; i <= 4;i++ )
            {

                TextBoxes[i].Text = Convert.ToString(c[i, 1]);
                TextBoxes[i + 4].Text = Convert.ToString(c[i, 2]);
                TextBoxes[i + 8].Text = Convert.ToString(c[i, 3]);
                TextBoxes[i + 12].Text = Convert.ToString(c[i, 4]);
                //使用for迴圈呈現答案於16個Textbox之中
            }
        }
    }
}

未完成的4X4矩陣(Use For loop)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        System.Windows.Forms.Button[] Buttons;
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int[,] a = new int[5, 5];
            int[,] b = new int[5, 5];
            int[,] c = new int[5, 5];
            int m=5,n=5 ;
            a[1, 1] = 1;
            a[1, 2] = 0;
            a[1, 3] = 0;
            a[1, 4] = 0;
            a[2, 1] = 0;
            a[2, 2] = 1;
            a[2, 3] = 0;
            a[2, 4] = 0;
            a[3, 1] = 0;
            a[3, 2] = 0;
            a[3, 3] = 1;
            a[3, 4] = 0;
            a[4, 1] = 0;
            a[4, 2] = 0;
            a[4, 3] = 0;
            a[4, 4] = 1;

            b[1, 1] = 1;
            b[1, 2] = 0;
            b[1, 3] = 0;
            b[1, 4] = 0;
            b[2, 1] = 0;
            b[2, 2] = 1;
            b[2, 3] = 0;
            b[2, 4] = 0;
            b[3, 1] = 0;
            b[3, 2] = 0;
            b[3, 3] = 1;
            b[3, 4] = 0;
            b[4, 1] = 0;
            b[4, 2] = 0;
            b[4, 3] = 0;
            b[4, 4] = 1;
            for (int i = 1; i < m; i++)
            {
                for (int j = 1; j < n; j++)
                {
                    for (int k = 1; k < m; k++)
                    {
                        c[i, j] = c[i, j] + a[i, k] * b[k, j];
                    }
                    Console.WriteLine(" c[" + i + ", " + j + "]=" + c[i, j]);
                }
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            Buttons = new System.Windows.Forms.Button[9];

            for (int i = 0; i < 9; ++i)
            {
                Buttons[i] = new Button();
                this.Controls.Add(Buttons[i]);
                if (i <= 2)
                    Buttons[i].Location = new System.Drawing.Point(10 + i * 80, 10);
                else if (i > 2 && i <= 5)
                    Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 80, 40);
                else if (i > 5 && i <= 9)
                    Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 80, 90);
            }
        }
    }
}

費氏數列

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[20];

            a[0] = a[1] = 1;
            Console.WriteLine("" + a[0]);
            Console.WriteLine("" + a[1]);
            for (int i = 2; i <  20; i++)
            {
              
                a[i] = a[i - 2] + a[i - 1];
                Console.WriteLine("" + a[i]);
            }
           
        
        }
    }
}

2010年10月8日 星期五

3X3矩陣運算

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int [,] a = new int[4,4];
            int [,] b = new int[4, 4];
            int [,] c = new int[4, 4];

            a[1, 1]=int.Parse(textBox10.Text);
            a[2, 1] = int.Parse(textBox11.Text);
            a[3, 1] = int.Parse(textBox12.Text);
            a[1, 2] = int.Parse(textBox13.Text);
            a[2, 2] = int.Parse(textBox14.Text);
            a[3, 2] = int.Parse(textBox15.Text);
            a[1, 3] = int.Parse(textBox16.Text);
            a[2, 3] = int.Parse(textBox17.Text);
            a[3, 3] = int.Parse(textBox18.Text);

            b[1, 1] = int.Parse(textBox19.Text);
            b[2, 1] = int.Parse(textBox20.Text);
            b[3, 1] = int.Parse(textBox21.Text);
            b[1, 2] = int.Parse(textBox22.Text);
            b[2, 2] = int.Parse(textBox23.Text);
            b[3, 2] = int.Parse(textBox24.Text);
            b[1, 3] = int.Parse(textBox25.Text);
            b[2, 3] = int.Parse(textBox26.Text);
            b[3, 3] = int.Parse(textBox27.Text);
           

            c[1, 1] = a[1, 1] * b[1, 1] + a[1, 2] * b[2, 1] + a[1, 3] * b[3, 1];
            c[1, 2] = a[1, 1] * b[1, 2] + a[1, 2] * b[2, 2] + a[1, 3] * b[3, 2];
            c[1, 3] = a[1, 1] * b[1, 3] + a[1, 2] * b[2, 3] + a[1, 3] * b[3, 3];
            c[2, 1] = a[2, 1] * b[1, 1] + a[2, 2] * b[2, 1] + a[2, 3] * b[3, 1];
            c[2, 2] = a[2, 1] * b[1, 2] + a[2, 2] * b[2, 2] + a[2, 3] * b[3, 2];
            c[2, 3] = a[2, 1] * b[1, 3] + a[2, 2] * b[2, 3] + a[2, 3] * b[3, 3];

            c[3, 1] = a[3, 1] * b[1, 1] + a[3, 2] * b[2, 1] + a[3, 3] * b[3, 1];
            c[3, 2] = a[3, 1] * b[1, 2] + a[3, 2] * b[2, 2] + a[3, 3] * b[3, 2];
            c[3, 3] = a[3, 1] * b[1, 3] + a[3, 2] * b[2, 3] + a[3, 3] * b[3, 3];

           textBox1.Text = Convert.ToString(c[1, 1]);
           textBox2.Text = Convert.ToString(c[1, 2]);
           textBox3.Text = Convert.ToString(c[1, 3]);
           textBox4.Text = Convert.ToString(c[2, 1]);
           textBox5.Text = Convert.ToString(c[2, 2]);
           textBox6.Text = Convert.ToString(c[2, 3]);
           textBox7.Text = Convert.ToString(c[3, 1]);
           textBox8.Text = Convert.ToString(c[3, 2]);
           textBox9.Text = Convert.ToString(c[3, 3]);
           

           
        }
        private void textBox2_TextChanged(object sender, EventArgs e)
        {
        }
        private void textBox13_TextChanged(object sender, EventArgs e)
        {
        }
        private void textBox10_TextChanged(object sender, EventArgs e)
        {
        }
    }
}