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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
System.Windows.Forms.TextBox[] textBox;
System.Windows.Forms.TextBox[] textBoxs;
System.Windows.Forms.Button[] Buttons;
int[,] a = new int[5, 5];
int[,] b = new int[5, 5];
int[,] c = new int[5, 5];
int m, n;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox = new System.Windows.Forms.TextBox[16];
for (int i = 0; i < 16; i++)
{
textBox[i] = new TextBox();
this.Controls.Add(textBox[i]);
if (i <= 3)
textBox[i].Location = new System.Drawing.Point(10 + i * 100, 10);
else if (i > 3 && i <= 7)
textBox[i].Location = new System.Drawing.Point(10 + (i - 4) * 100, 40);
else if (i > 7 && i <= 11)
textBox[i].Location = new System.Drawing.Point(10 + (i - 8) * 100, 70);
else if (i > 11 && i <= 15)
textBox[i].Location = new System.Drawing.Point(10 + (i - 12) * 100, 100);
}
textBoxs = new System.Windows.Forms.TextBox[16];
for (int i = 0; i < 16; i++)
{
textBoxs[i] = new TextBox();
this.Controls.Add(textBoxs[i]);
if (i <= 3)
textBoxs[i].Location = new System.Drawing.Point(10 + i * 100+500, 10);
else if (i > 3 && i <= 7)
textBoxs[i].Location = new System.Drawing.Point(10 + (i - 4) * 100 + 500, 40);
else if (i > 7 && i <= 11)
textBoxs[i].Location = new System.Drawing.Point(10 + (i - 8) * 100 + 500, 70);
else if (i > 11 && i <= 15)
textBoxs[i].Location = new System.Drawing.Point(10 + (i - 12) * 100 + 500, 100);
}
Buttons = new System.Windows.Forms.Button[16];
for (int i = 0; i < 16; i++)
{
Buttons[i] = new Button();
this.Controls.Add(Buttons[i]);
if (i <= 3)
Buttons[i].Location = new System.Drawing.Point(10 + i * 80, 10 + 200);
else if (i > 3 && i <= 7)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 4) * 80, 40 + 200);
else if (i > 7 && i <= 11)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 8) * 80, 70 + 200);
else if (i > 11 && i <= 15)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 12) * 80, 100 + 200);
}
textBox[0].Text = "1";
textBox[1].Text = "0";
textBox[2].Text = "0";
textBox[3].Text = "0";
textBox[4].Text = "0";
textBox[5].Text = "1";
textBox[6].Text = "0";
textBox[7].Text = "0";
textBox[8].Text = "0";
textBox[9].Text = "0";
textBox[10].Text = "1";
textBox[11].Text = "0";
textBox[12].Text = "0";
textBox[13].Text = "0";
textBox[14].Text = "0";
textBox[15].Text = "1";
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";
}
private void button1_Click(object sender, EventArgs e)
{
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];
}
}
}
//input
a[1, 1] = Convert.ToInt16(textBox[0].Text);
a[1, 2] = Convert.ToInt16(textBox[1].Text);
a[1, 3] = Convert.ToInt16(textBox[2].Text);
a[1, 4] = Convert.ToInt16(textBox[3].Text);
a[2, 1] = Convert.ToInt16(textBox[4].Text);
a[2, 2] = Convert.ToInt16(textBox[5].Text);
a[2, 3] = Convert.ToInt16(textBox[6].Text);
a[2, 4] = Convert.ToInt16(textBox[7].Text);
a[3, 1] = Convert.ToInt16(textBox[8].Text);
a[3, 2] = Convert.ToInt16(textBox[9].Text);
a[3, 3] = Convert.ToInt16(textBox[10].Text);
a[3, 4] = Convert.ToInt16(textBox[11].Text);
a[4, 1] = Convert.ToInt16(textBox[12].Text);
a[4, 2] = Convert.ToInt16(textBox[13].Text);
a[4, 3] = Convert.ToInt16(textBox[14].Text);
a[4, 4] = Convert.ToInt16(textBox[15].Text);
//output
for (int i = 0; i < 16; ++i)
if (i < 4)
{
Buttons[i].Text = Convert.ToString(a[1, i + 1]);
}
else if (i >= 4 && i < 8)
{
Buttons[i].Text = Convert.ToString(a[2, (i - 4) + 1]);
}
else if (i >= 8 && i < 12)
{
Buttons[i].Text = Convert.ToString(a[3, (i - 4 * 2) + 1]);
}
else
{
Buttons[i].Text = Convert.ToString(a[4, (i - 4 * 3) + 1]);
}
}
}
}
沒有留言:
張貼留言