2010年10月22日 星期五

33333333

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.TextBox[] textboxs;
        int[,] a = new int[5, 5];
        int[,] b = new int[5, 5];
        int[,] c = new int[5, 5];
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            textboxs = new System.Windows.Forms.TextBox[48];
            for (int j = 0; j < 48; j++)
            {
                textboxs[j] = new TextBox();
                this.Controls.Add(textboxs[j]);
                if (j <= 3)
                    textboxs[j].Location = new System.Drawing.Point(10 + j * 110, 10);
                else if (j > 3 && j <= 7)
                    textboxs[j].Location = new System.Drawing.Point(10 + (j - 4) * 110, 40);
                else if (j > 7 && j <= 11)
                    textboxs[j].Location = new System.Drawing.Point(10 + (j - 8) * 110, 70);
                else if (j > 11 && j <= 15)
                    textboxs[j].Location = new System.Drawing.Point(10 + (j - 12) * 110, 100);
                else if (j > 15 && j <= 19)
                    textboxs[j].Location = new System.Drawing.Point(10 + (j - 16) * 110, 140);
                else if (j > 19 && j <= 23)
                    textboxs[j].Location = new System.Drawing.Point(10 + (j - 20) * 110, 170);
                else if (j > 23 && j <= 27)
                    textboxs[j].Location = new System.Drawing.Point(10 + (j - 24) * 110, 200);
                else if (j > 27 && j <= 31)
                    textboxs[j].Location = new System.Drawing.Point(10 + (j - 28) * 110, 230);
                else if (j > 31 && j <= 35)
                    textboxs[j].Location = new System.Drawing.Point(10 + (j - 32) * 110, 270);
                else if (j > 35 && j <= 39)
                    textboxs[j].Location = new System.Drawing.Point(10 + (j - 36) * 110, 300);
                else if (j > 39 && j <= 43)
                    textboxs[j].Location = new System.Drawing.Point(10 + (j - 40) * 110, 330);
                else if (j > 43 && j <= 47)
                    textboxs[j].Location = new System.Drawing.Point(10 + (j - 44) * 110, 360);
            }
            textboxs[0].Text = "1";
            textboxs[1].Text = "0";
            textboxs[2].Text = "0";
            textboxs[3].Text = "0";
            textboxs[4].Text = "0";
            textboxs[5].Text = "1";
            textboxs[6].Text = "0";
            textboxs[7].Text = "0";
            textboxs[8].Text = "0";
            textboxs[9].Text = "0";
            textboxs[10].Text = "1";
            textboxs[11].Text = "0";
            textboxs[12].Text = "0";
            textboxs[13].Text = "0";
            textboxs[14].Text = "0";
            textboxs[15].Text = "1";
            textboxs[16].Text = "1";
            textboxs[17].Text = "0";
            textboxs[18].Text = "0";
            textboxs[19].Text = "0";
            textboxs[20].Text = "0";
            textboxs[21].Text = "1";
            textboxs[22].Text = "0";
            textboxs[23].Text = "0";
            textboxs[24].Text = "0";
            textboxs[25].Text = "0";
            textboxs[26].Text = "1";
            textboxs[27].Text = "0";
            textboxs[28].Text = "0";
            textboxs[29].Text = "0";
            textboxs[30].Text = "0";
            textboxs[31].Text = "1";
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //輸入 intput
            for (int i = 0; i < 16; i++)
            {
                if (i <= 3)
                    a[1, i + 1] = Convert.ToInt16(textboxs[i].Text);
                else if (i > 3 && i <= 7)
                    a[2, (i - 4) + 1] = Convert.ToInt16(textboxs[i].Text);
                else if (i > 7 && i <= 11)
                    a[3, (i - 8) + 1] = Convert.ToInt16(textboxs[i].Text);
                else if (i > 11 && i <= 15)
                    a[4, (i - 12) + 1] = Convert.ToInt16(textboxs[i].Text);
            }
            for (int i = 0; i < 16; i++)
            {
                if (i <= 3)
                    b[1, i + 1] = Convert.ToInt16(textboxs[(i + 16)].Text);
                else if (i > 3 && i <= 7)
                    b[2, (i - 4) + 1] = Convert.ToInt16(textboxs[(i + 16)].Text);
                else if (i > 7 && i <= 11)
                    b[3, (i - 8) + 1] = Convert.ToInt16(textboxs[(i + 16)].Text);
                else if (i > 11 && i <= 15)
                    b[4, (i - 12) + 1] = Convert.ToInt16(textboxs[(i + 16)].Text);
            }
            c[1, 1] = a[1, 1] * b[1, 1] + a[1, 2] * b[2, 1] + a[1, 3] * b[3, 1] + a[1, 4] * b[4, 1];
            c[1, 2] = a[1, 1] * b[1, 2] + a[1, 2] * b[2, 2] + a[1, 3] * b[3, 2] + a[1, 4] * b[4, 2];
            c[1, 3] = a[1, 1] * b[1, 3] + a[1, 2] * b[2, 3] + a[1, 3] * b[3, 3] + a[1, 4] * b[4, 3];
            c[1, 4] = a[1, 1] * b[1, 4] + a[1, 2] * b[2, 4] + a[1, 3] * b[3, 4] + a[1, 4] * b[4, 4];
            c[2, 1] = a[2, 1] * b[1, 1] + a[2, 2] * b[2, 1] + a[2, 3] * b[3, 1] + a[2, 4] * b[4, 1];
            c[2, 2] = a[2, 1] * b[1, 2] + a[2, 2] * b[2, 2] + a[2, 3] * b[3, 2] + a[2, 4] * b[4, 2];
            c[2, 3] = a[2, 1] * b[1, 3] + a[2, 2] * b[2, 3] + a[2, 3] * b[3, 3] + a[2, 4] * b[4, 3];
            c[2, 4] = a[2, 1] * b[1, 4] + a[2, 2] * b[2, 4] + a[2, 3] * b[3, 4] + a[2, 4] * b[4, 4];
            c[3, 1] = a[3, 1] * b[1, 1] + a[3, 2] * b[2, 1] + a[3, 3] * b[3, 1] + a[3, 4] * b[4, 1];
            c[3, 2] = a[3, 1] * b[1, 2] + a[3, 2] * b[2, 2] + a[3, 3] * b[3, 2] + a[3, 4] * b[4, 2];
            c[3, 3] = a[3, 1] * b[1, 3] + a[3, 2] * b[2, 3] + a[3, 3] * b[3, 3] + a[3, 4] * b[4, 3];
            c[3, 4] = a[3, 1] * b[1, 4] + a[3, 2] * b[2, 4] + a[3, 3] * b[3, 4] + a[3, 4] * b[4, 4];
            c[4, 1] = a[4, 1] * b[1, 1] + a[4, 2] * b[2, 1] + a[4, 3] * b[3, 1] + a[4, 4] * b[4, 1];
            c[4, 2] = a[4, 1] * b[1, 2] + a[4, 2] * b[2, 2] + a[4, 3] * b[3, 2] + a[4, 4] * b[4, 2];
            c[4, 3] = a[4, 1] * b[1, 3] + a[4, 2] * b[2, 3] + a[4, 3] * b[3, 3] + a[4, 4] * b[4, 3];
            c[4, 4] = a[4, 1] * b[1, 4] + a[4, 2] * b[2, 4] + a[4, 3] * b[3, 4] + a[4, 4] * b[4, 4];
            textboxs[32].Text = "" + c[1, 1];
            textboxs[33].Text = "" + c[1, 2];
            textboxs[34].Text = "" + c[1, 3];
            textboxs[35].Text = "" + c[1, 4];
            textboxs[36].Text = "" + c[2, 1];
            textboxs[37].Text = "" + c[2, 2];
            textboxs[38].Text = "" + c[2, 3];
            textboxs[39].Text = "" + c[2, 4];
            textboxs[40].Text = "" + c[3, 1];
            textboxs[41].Text = "" + c[3, 2];
            textboxs[42].Text = "" + c[3, 3];
            textboxs[43].Text = "" + c[3, 4];
            textboxs[44].Text = "" + c[4, 1];
            textboxs[45].Text = "" + c[4, 2];
            textboxs[46].Text = "" + c[4, 3];
            textboxs[47].Text = "" + c[4, 4];

        }
    }
}

沒有留言:

張貼留言