2010年10月8日 星期五

10/8 作業3*3矩陣相乘

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
    {
        Form2 newform;
        public Form1()
        {
            InitializeComponent();
        }
        private void label1_Click(object sender, EventArgs e)
        {
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int a=0, b=0, c;
            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;
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 d, x, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w;
            String output;
            d = int.Parse(textBox9.Text);
            x = int.Parse(textBox8.Text);
            f = int.Parse(textBox7.Text);
            g = int.Parse(textBox6.Text);
            h = int.Parse(textBox5.Text);
            i = int.Parse(textBox4.Text);
            j = int.Parse(textBox3.Text);
            k = int.Parse(textBox2.Text);
            l = int.Parse(textBox1.Text);
            m = int.Parse(textBox18.Text);
            n = int.Parse(textBox17.Text);
            o = int.Parse(textBox16.Text);
            p = int.Parse(textBox15.Text);
            q = int.Parse(textBox14.Text);
            r = int.Parse(textBox13.Text);
            s = int.Parse(textBox12.Text);
            t = int.Parse(textBox11.Text);
            u = int.Parse(textBox10.Text);
            int[,] a = new int[4,4];
            int[,] b = new int[4,4];
            int[,] c = new int[4,4];
            a[1, 1] = d;
            a[1, 2] = x;
            a[1, 3] = f;
            a[2, 1] = g;
            a[2, 2] = h;
            a[2, 3] = i;
            a[3, 1] = j;
            a[3, 2] = k;
            a[3, 3] = l;
            b[1, 1] = m;
            b[1, 2] = n;
            b[1, 3] = o;
            b[2, 1] = p;
            b[2, 2] = q;
            b[2, 3] = r;
            b[3, 1] = s;
            b[3, 2] = t;
            b[3, 3] = u;
            c[1, 1] = 0;
            c[1, 2] = 0;
            c[1, 3] = 0;
            c[2, 1] = 0;
            c[2, 2] = 0;
            c[2, 3] = 0;
            c[3, 1] = 0;
            c[3, 2] = 0;
            c[3, 3] = 0;
            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];


    
            textBox19.Text = Convert.ToString(c[1, 1]);
            textBox20.Text = Convert.ToString(c[1, 2]);
            textBox21.Text = Convert.ToString(c[1, 3]);
            textBox22.Text = Convert.ToString(c[2, 1]);
            textBox23.Text = Convert.ToString(c[2, 2]);
            textBox24.Text = Convert.ToString(c[2, 3]);
            textBox25.Text = Convert.ToString(c[3, 1]);
            textBox26.Text = Convert.ToString(c[3, 2]);
            textBox27.Text = Convert.ToString(c[3, 3]);
          
           
        }
    }
}

沒有留言:

張貼留言