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[] TextBoxes;
int[,] a = new int[4, 4];
int bno;
public Form1()
{
InitializeComponent();
}
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();
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 * 80, 10 + 100);
else if (i > 2 && i <= 5)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 80, 40 + 100);
else if (i > 5 && i <= 9)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 80, 70 + 100);
}
TextBoxes = new System.Windows.Forms.TextBox[9];
for (int i = 0; i < 9; ++i)
{
TextBoxes[i] = new TextBox();
this.Controls.Add(TextBoxes[i]);
if (i <= 2)
TextBoxes[i].Location = new System.Drawing.Point(10 + i * 100, 10);
else if (i > 2 && i <= 5)
TextBoxes[i].Location = new System.Drawing.Point(10 + (i - 3) * 100, 40);
else if (i > 5 && i <= 9)
TextBoxes[i].Location = new System.Drawing.Point(10 + (i - 6) * 100, 70);
}
TextBoxes[0].Text = "7";
TextBoxes[1].Text = "2";
TextBoxes[2].Text = "4";
TextBoxes[3].Text = "5";
TextBoxes[4].Text = "0";
TextBoxes[5].Text = "6";
TextBoxes[6].Text = "8";
TextBoxes[7].Text = "3";
TextBoxes[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());
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[2].Text == "0")
{
String temp;
temp = Buttons[2].Text;
Buttons[2].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;
}
break;
case 2:
if (Buttons[5].Text == "0")
{
String temp;
temp = Buttons[5].Text;
Buttons[5].Text = Buttons[2].Text;
Buttons[2].Text = temp;
}
if (Buttons[1].Text == "0")
{
String temp;
temp = Buttons[1].Text;
Buttons[1].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[6].Text == "0")
{
String temp;
temp = Buttons[6].Text;
Buttons[6].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;
}
break;
case 4:
if (Buttons[5].Text == "0")
{
String temp;
temp = Buttons[5].Text;
Buttons[5].Text = Buttons[4].Text;
Buttons[4].Text = temp;
}
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[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[8].Text == "0")
{
String temp;
temp = Buttons[8].Text;
Buttons[8].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;
}
break;
case 6:
if (Buttons[7].Text == "0")
{
String temp;
temp = Buttons[7].Text;
Buttons[7].Text = Buttons[6].Text;
Buttons[6].Text = temp;
}
if (Buttons[3].Text == "0")
{
String temp;
temp = Buttons[3].Text;
Buttons[3].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)
{
//輸入 intput
a[1, 1] = Convert.ToInt16(TextBoxes[0].Text);
a[1, 2] = Convert.ToInt16(TextBoxes[1].Text);
a[1, 3] = Convert.ToInt16(TextBoxes[2].Text);
a[2, 1] = Convert.ToInt16(TextBoxes[3].Text);
a[2, 2] = Convert.ToInt16(TextBoxes[4].Text);
a[2, 3] = Convert.ToInt16(TextBoxes[5].Text);
a[3, 1] = Convert.ToInt16(TextBoxes[6].Text);
a[3, 2] = Convert.ToInt16(TextBoxes[7].Text);
a[3, 3] = Convert.ToInt16(TextBoxes[8].Text);
//輸出 output
for (int i = 0; i < 9; ++i)
if (i < 3)
{
Buttons[i].Text = Convert.ToString(a[1, i + 1]);
}
else if (i >= 3 && i < 6)
{
Buttons[i].Text = Convert.ToString(a[2, (i - 3) + 1]);
}
else if (i >= 6 && i < 9)
{
Buttons[i].Text = Convert.ToString(a[3, (i - 3 * 2) + 1]);
}
}
}
}
2010年10月29日 星期五
2010年10月15日 星期五
4*4 矩陣
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[] textbox1;
System.Windows.Forms.TextBox[] textbox2;
System.Windows.Forms.TextBox[] textbox3;
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)
{
textbox1 = new System.Windows.Forms.TextBox[16];
for (int i = 0; i < 16; i++)
{
textbox1[i] = new TextBox();
this.Controls.Add(textbox1[i]);
if (i <= 3)
textbox1[i].Location = new System.Drawing.Point(10 + i * 100, 10);
else if (i > 3 && i <= 7)
textbox1[i].Location = new System.Drawing.Point(10 + (i - 4) * 100, 40);
else if (i > 7 && i <= 11)
textbox1[i].Location = new System.Drawing.Point(10 + (i - 8) * 100, 70);
else if (i > 11 && i <= 15)
textbox1[i].Location = new System.Drawing.Point(10 + (i - 12) * 100, 100);
}
textbox2 = new System.Windows.Forms.TextBox[16];
for (int i = 0; i < 16; i++)
{
textbox2[i] = new TextBox();
this.Controls.Add(textbox2[i]);
if (i <= 3)
textbox2[i].Location = new System.Drawing.Point(10 + i * 100, 160);
else if (i > 3 && i <= 7)
textbox2[i].Location = new System.Drawing.Point(10 + (i - 4) * 100, 190);
else if (i > 7 && i <= 11)
textbox2[i].Location = new System.Drawing.Point(10 + (i - 8) * 100, 220);
else if (i > 11 && i <= 15)
textbox2[i].Location = new System.Drawing.Point(10 + (i - 12) * 100, 260);
}
textbox3 = new System.Windows.Forms.TextBox[16];
for (int i = 0; i < 16; i++)
{
textbox3[i] = new TextBox();
this.Controls.Add(textbox3[i]);
if (i <= 3)
textbox3[i].Location = new System.Drawing.Point(10 + i * 100, 300);
else if (i > 3 && i <= 7)
textbox3[i].Location = new System.Drawing.Point(10 + (i - 4) * 100, 330);
else if (i > 7 && i <= 11)
textbox3[i].Location = new System.Drawing.Point(10 + (i - 8) * 100, 360);
else if (i > 11 && i <= 15)
textbox3[i].Location = new System.Drawing.Point(10 + (i - 12) * 100, 390);
}
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 1; i < 5; i++)
for (int j = 1; j < 5; j++)
{
for (int k = 1; k < 5; k++)
{
c[i, j] = c[i, j] + a[i, k] * b[k, j];
c[i = 1, j] = c[i = 1, j] + a[1, 1] * b[i, j] + a[1, 2] * b[i + 1, j] + a[1, 3] * b[i + 2, j] + a[1, 4] * b[i + 3, j];
c[i = 2, j] = c[i = 2, j] + a[2, 1] * b[i - 1, j] + a[2, 2] * b[i, j] + a[2, 3] * b[i + 1, j] + a[2, 4] * b[i + 2, j];
c[i = 3, j] = c[i = 3, j] + a[3, 1] * b[i - 2, j] + a[3, 2] * b[i - 1, j] + a[3, 3] * b[i, j] + a[3, 4] * b[i + 1, j];
c[i = 4, j] = c[i = 4, j] + a[4, 1] * b[i - 3, j] + a[4, 2] * b[i - 2, j] + a[4, 3] * b[i - 1, j] + a[4, 4] * b[i, j];
}
}
//input
a[1, 1] = Convert.ToInt16(textbox1[0].Text);
a[1, 2] = Convert.ToInt16(textbox1[1].Text);
a[1, 3] = Convert.ToInt16(textbox1[2].Text);
a[1, 4] = Convert.ToInt16(textbox1[3].Text);
a[2, 1] = Convert.ToInt16(textbox1[4].Text);
a[2, 2] = Convert.ToInt16(textbox1[5].Text);
a[2, 3] = Convert.ToInt16(textbox1[6].Text);
a[2, 4] = Convert.ToInt16(textbox1[7].Text);
a[3, 1] = Convert.ToInt16(textbox1[8].Text);
a[3, 2] = Convert.ToInt16(textbox1[9].Text);
a[3, 3] = Convert.ToInt16(textbox1[10].Text);
a[3, 4] = Convert.ToInt16(textbox1[11].Text);
a[4, 1] = Convert.ToInt16(textbox1[12].Text);
a[4, 2] = Convert.ToInt16(textbox1[13].Text);
a[4, 3] = Convert.ToInt16(textbox1[14].Text);
a[4, 4] = Convert.ToInt16(textbox1[15].Text);
b[1, 1] = Convert.ToInt16(textbox2[0].Text);
b[1, 2] = Convert.ToInt16(textbox2[1].Text);
b[1, 3] = Convert.ToInt16(textbox2[2].Text);
b[1, 4] = Convert.ToInt16(textbox2[3].Text);
b[2, 1] = Convert.ToInt16(textbox2[4].Text);
b[2, 2] = Convert.ToInt16(textbox2[5].Text);
b[2, 3] = Convert.ToInt16(textbox2[6].Text);
b[2, 4] = Convert.ToInt16(textbox2[7].Text);
b[3, 1] = Convert.ToInt16(textbox2[8].Text);
b[3, 2] = Convert.ToInt16(textbox2[9].Text);
b[3, 3] = Convert.ToInt16(textbox2[10].Text);
b[3, 4] = Convert.ToInt16(textbox2[11].Text);
b[4, 1] = Convert.ToInt16(textbox2[12].Text);
b[4, 2] = Convert.ToInt16(textbox2[13].Text);
b[4, 3] = Convert.ToInt16(textbox2[14].Text);
b[4, 4] = Convert.ToInt16(textbox2[15].Text);
for (int i = 1; i < 5; i++)
for (int j = 1; j < 5; j++)
{
c[i = 1, j] = a[1, 1] * b[i, j] + a[1, 2] * b[i + 1, j] + a[1, 3] * b[i + 2, j] + a[1, 4] * b[i + 3, j];
c[i = 2, j] =a[2, 1] * b[i - 1, j] + a[2, 2] * b[i, j] + a[2, 3] * b[i + 1, j] + a[2, 4] * b[i + 2, j];
c[i = 3, j] = a[3, 1] * b[i - 2, j] + a[3, 2] * b[i - 1, j] + a[3, 3] * b[i, j] + a[3, 4] * b[i + 1, j];
c[i = 4, j] = a[4, 1] * b[i - 3, j] + a[4, 2] * b[i - 2, j] + a[4, 3] * b[i - 1, j] + a[4, 4] * b[i, j];
}
//output
for (int i = 0; i < 16; ++i)
if (i < 4)
{
textbox3[i].Text = Convert.ToString(c[1, i + 1]);
}
else if (i >= 4 && i < 8)
{
textbox3[i].Text = Convert.ToString(c[2, (i - 4) + 1]);
}
else if (i >= 8 && i < 12)
{
textbox3[i].Text = Convert.ToString(c[3, (i - 4 * 2) + 1]);
}
else
{
textbox3[i].Text = Convert.ToString(c[4, (i - 4 * 3) + 1]);
}
}
}
}
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[] textbox1;
System.Windows.Forms.TextBox[] textbox2;
System.Windows.Forms.TextBox[] textbox3;
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)
{
textbox1 = new System.Windows.Forms.TextBox[16];
for (int i = 0; i < 16; i++)
{
textbox1[i] = new TextBox();
this.Controls.Add(textbox1[i]);
if (i <= 3)
textbox1[i].Location = new System.Drawing.Point(10 + i * 100, 10);
else if (i > 3 && i <= 7)
textbox1[i].Location = new System.Drawing.Point(10 + (i - 4) * 100, 40);
else if (i > 7 && i <= 11)
textbox1[i].Location = new System.Drawing.Point(10 + (i - 8) * 100, 70);
else if (i > 11 && i <= 15)
textbox1[i].Location = new System.Drawing.Point(10 + (i - 12) * 100, 100);
}
textbox2 = new System.Windows.Forms.TextBox[16];
for (int i = 0; i < 16; i++)
{
textbox2[i] = new TextBox();
this.Controls.Add(textbox2[i]);
if (i <= 3)
textbox2[i].Location = new System.Drawing.Point(10 + i * 100, 160);
else if (i > 3 && i <= 7)
textbox2[i].Location = new System.Drawing.Point(10 + (i - 4) * 100, 190);
else if (i > 7 && i <= 11)
textbox2[i].Location = new System.Drawing.Point(10 + (i - 8) * 100, 220);
else if (i > 11 && i <= 15)
textbox2[i].Location = new System.Drawing.Point(10 + (i - 12) * 100, 260);
}
textbox3 = new System.Windows.Forms.TextBox[16];
for (int i = 0; i < 16; i++)
{
textbox3[i] = new TextBox();
this.Controls.Add(textbox3[i]);
if (i <= 3)
textbox3[i].Location = new System.Drawing.Point(10 + i * 100, 300);
else if (i > 3 && i <= 7)
textbox3[i].Location = new System.Drawing.Point(10 + (i - 4) * 100, 330);
else if (i > 7 && i <= 11)
textbox3[i].Location = new System.Drawing.Point(10 + (i - 8) * 100, 360);
else if (i > 11 && i <= 15)
textbox3[i].Location = new System.Drawing.Point(10 + (i - 12) * 100, 390);
}
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 1; i < 5; i++)
for (int j = 1; j < 5; j++)
{
for (int k = 1; k < 5; k++)
{
c[i, j] = c[i, j] + a[i, k] * b[k, j];
c[i = 1, j] = c[i = 1, j] + a[1, 1] * b[i, j] + a[1, 2] * b[i + 1, j] + a[1, 3] * b[i + 2, j] + a[1, 4] * b[i + 3, j];
c[i = 2, j] = c[i = 2, j] + a[2, 1] * b[i - 1, j] + a[2, 2] * b[i, j] + a[2, 3] * b[i + 1, j] + a[2, 4] * b[i + 2, j];
c[i = 3, j] = c[i = 3, j] + a[3, 1] * b[i - 2, j] + a[3, 2] * b[i - 1, j] + a[3, 3] * b[i, j] + a[3, 4] * b[i + 1, j];
c[i = 4, j] = c[i = 4, j] + a[4, 1] * b[i - 3, j] + a[4, 2] * b[i - 2, j] + a[4, 3] * b[i - 1, j] + a[4, 4] * b[i, j];
}
}
//input
a[1, 1] = Convert.ToInt16(textbox1[0].Text);
a[1, 2] = Convert.ToInt16(textbox1[1].Text);
a[1, 3] = Convert.ToInt16(textbox1[2].Text);
a[1, 4] = Convert.ToInt16(textbox1[3].Text);
a[2, 1] = Convert.ToInt16(textbox1[4].Text);
a[2, 2] = Convert.ToInt16(textbox1[5].Text);
a[2, 3] = Convert.ToInt16(textbox1[6].Text);
a[2, 4] = Convert.ToInt16(textbox1[7].Text);
a[3, 1] = Convert.ToInt16(textbox1[8].Text);
a[3, 2] = Convert.ToInt16(textbox1[9].Text);
a[3, 3] = Convert.ToInt16(textbox1[10].Text);
a[3, 4] = Convert.ToInt16(textbox1[11].Text);
a[4, 1] = Convert.ToInt16(textbox1[12].Text);
a[4, 2] = Convert.ToInt16(textbox1[13].Text);
a[4, 3] = Convert.ToInt16(textbox1[14].Text);
a[4, 4] = Convert.ToInt16(textbox1[15].Text);
b[1, 1] = Convert.ToInt16(textbox2[0].Text);
b[1, 2] = Convert.ToInt16(textbox2[1].Text);
b[1, 3] = Convert.ToInt16(textbox2[2].Text);
b[1, 4] = Convert.ToInt16(textbox2[3].Text);
b[2, 1] = Convert.ToInt16(textbox2[4].Text);
b[2, 2] = Convert.ToInt16(textbox2[5].Text);
b[2, 3] = Convert.ToInt16(textbox2[6].Text);
b[2, 4] = Convert.ToInt16(textbox2[7].Text);
b[3, 1] = Convert.ToInt16(textbox2[8].Text);
b[3, 2] = Convert.ToInt16(textbox2[9].Text);
b[3, 3] = Convert.ToInt16(textbox2[10].Text);
b[3, 4] = Convert.ToInt16(textbox2[11].Text);
b[4, 1] = Convert.ToInt16(textbox2[12].Text);
b[4, 2] = Convert.ToInt16(textbox2[13].Text);
b[4, 3] = Convert.ToInt16(textbox2[14].Text);
b[4, 4] = Convert.ToInt16(textbox2[15].Text);
for (int i = 1; i < 5; i++)
for (int j = 1; j < 5; j++)
{
c[i = 1, j] = a[1, 1] * b[i, j] + a[1, 2] * b[i + 1, j] + a[1, 3] * b[i + 2, j] + a[1, 4] * b[i + 3, j];
c[i = 2, j] =a[2, 1] * b[i - 1, j] + a[2, 2] * b[i, j] + a[2, 3] * b[i + 1, j] + a[2, 4] * b[i + 2, j];
c[i = 3, j] = a[3, 1] * b[i - 2, j] + a[3, 2] * b[i - 1, j] + a[3, 3] * b[i, j] + a[3, 4] * b[i + 1, j];
c[i = 4, j] = a[4, 1] * b[i - 3, j] + a[4, 2] * b[i - 2, j] + a[4, 3] * b[i - 1, j] + a[4, 4] * b[i, j];
}
//output
for (int i = 0; i < 16; ++i)
if (i < 4)
{
textbox3[i].Text = Convert.ToString(c[1, i + 1]);
}
else if (i >= 4 && i < 8)
{
textbox3[i].Text = Convert.ToString(c[2, (i - 4) + 1]);
}
else if (i >= 8 && i < 12)
{
textbox3[i].Text = Convert.ToString(c[3, (i - 4 * 2) + 1]);
}
else
{
textbox3[i].Text = Convert.ToString(c[4, (i - 4 * 3) + 1]);
}
}
}
}
2010年10月8日 星期五
A與B都是3*3 的矩陣,求相乘結果 (10/8)
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 Form2 : Form
{
public Form2()
{
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];
String output;
a[1,1] = int.Parse(textBox1.Text);
a[1, 2] = int.Parse(textBox2.Text);
a[1, 3] = int.Parse(textBox3.Text);
a[2, 1] = int.Parse(textBox4.Text);
a[2, 2] = int.Parse(textBox5.Text);
a[2, 3] = int.Parse(textBox6.Text);
a[3, 1] = int.Parse(textBox7.Text);
a[3, 2] = int.Parse(textBox8.Text);
a[3, 3] = int.Parse(textBox9.Text);
b[1, 1] = int.Parse(textBox10.Text);
b[1, 2] = int.Parse(textBox11.Text);
b[1, 3] = int.Parse(textBox12.Text);
b[2, 1] = int.Parse(textBox13.Text);
b[2, 2] = int.Parse(textBox14.Text);
b[2, 3] = int.Parse(textBox15.Text);
b[3, 1] = int.Parse(textBox16.Text);
b[3, 2] = int.Parse(textBox17.Text);
b[3, 3] = int.Parse(textBox18.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];
output = Convert.ToString(c[1,1]);
textBox19.Text = output;
output = Convert.ToString(c[1, 2]);
textBox20.Text = output;
output = Convert.ToString(c[1, 3]);
textBox21.Text = output;
output = Convert.ToString(c[2, 1]);
textBox22.Text = output;
output = Convert.ToString(c[2, 2]);
textBox23.Text = output;
output = Convert.ToString(c[2, 3]);
textBox24.Text = output;
output = Convert.ToString(c[3, 1]);
textBox25.Text = output;
output = Convert.ToString(c[3, 2]);
textBox26.Text = output;
output = Convert.ToString(c[3, 3]);
textBox27.Text = output;
}
}
}
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 Form2 : Form
{
public Form2()
{
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];
String output;
a[1,1] = int.Parse(textBox1.Text);
a[1, 2] = int.Parse(textBox2.Text);
a[1, 3] = int.Parse(textBox3.Text);
a[2, 1] = int.Parse(textBox4.Text);
a[2, 2] = int.Parse(textBox5.Text);
a[2, 3] = int.Parse(textBox6.Text);
a[3, 1] = int.Parse(textBox7.Text);
a[3, 2] = int.Parse(textBox8.Text);
a[3, 3] = int.Parse(textBox9.Text);
b[1, 1] = int.Parse(textBox10.Text);
b[1, 2] = int.Parse(textBox11.Text);
b[1, 3] = int.Parse(textBox12.Text);
b[2, 1] = int.Parse(textBox13.Text);
b[2, 2] = int.Parse(textBox14.Text);
b[2, 3] = int.Parse(textBox15.Text);
b[3, 1] = int.Parse(textBox16.Text);
b[3, 2] = int.Parse(textBox17.Text);
b[3, 3] = int.Parse(textBox18.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];
output = Convert.ToString(c[1,1]);
textBox19.Text = output;
output = Convert.ToString(c[1, 2]);
textBox20.Text = output;
output = Convert.ToString(c[1, 3]);
textBox21.Text = output;
output = Convert.ToString(c[2, 1]);
textBox22.Text = output;
output = Convert.ToString(c[2, 2]);
textBox23.Text = output;
output = Convert.ToString(c[2, 3]);
textBox24.Text = output;
output = Convert.ToString(c[3, 1]);
textBox25.Text = output;
output = Convert.ToString(c[3, 2]);
textBox26.Text = output;
output = Convert.ToString(c[3, 3]);
textBox27.Text = output;
}
}
}
How to: Convert a string to an int (C# Programming Guide)
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
{
Form2 newform;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int a=0, b=0, c=0;
String output;
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = a * b;
output = Convert.ToString(c);
textBox3.Text = output;
}
private void button2_Click(object sender, EventArgs e)
{
newform = new Form2();
newform.Show();
}
}
}
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
{
Form2 newform;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int a=0, b=0, c=0;
String output;
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = a * b;
output = Convert.ToString(c);
textBox3.Text = output;
}
private void button2_Click(object sender, EventArgs e)
{
newform = new Form2();
newform.Show();
}
}
}
2010年10月1日 星期五
九九乘法 part2
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 Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int[,] array = new int[10, 10];
for (int x = 1; x <= 9; x++)
{
for (int y = 1; y <= 9; y++)
{
array[x, y] = x * y;
}
}
for (int z = 1; z <= 9; z++)
{
listBox1.Items.Add("" + z + "*1=" + array[z, 1] + "" + z + "*2=" + array[z, 2] + "" + z+ "*3=" + array[z, 3] + "" + z+ "*4=" + array[z, 4] + "" + z + "*5=" + array[z, 5] + "" + z + "*6=" + array[z, 6] + "" + z + "*7=" + array[z, 7] + "" + z+ "*8=" + array[z, 8] + "" + z + "*9=" + array[z, 9]);
}
}
}
}
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 Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int[,] array = new int[10, 10];
for (int x = 1; x <= 9; x++)
{
for (int y = 1; y <= 9; y++)
{
array[x, y] = x * y;
}
}
for (int z = 1; z <= 9; z++)
{
listBox1.Items.Add("" + z + "*1=" + array[z, 1] + "" + z + "*2=" + array[z, 2] + "" + z+ "*3=" + array[z, 3] + "" + z+ "*4=" + array[z, 4] + "" + z + "*5=" + array[z, 5] + "" + z + "*6=" + array[z, 6] + "" + z + "*7=" + array[z, 7] + "" + z+ "*8=" + array[z, 8] + "" + z + "*9=" + array[z, 9]);
}
}
}
}
訂閱:
文章 (Atom)