2010年10月8日 星期五

2010/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
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void label1_Click(object sender, EventArgs e)
        {
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int a, b, c;
            string output;
            a = int.Parse(textBox1.Text);
            b = int.Parse(textBox2.Text);
            c = a * b;
            output =Convert.ToString(c);
            textBox3.Text = output;
        }
        Form2 newform;
        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 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];
            String g1, g2, g3, g4, g5, g6, g7, g8, g9;
            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];

            g1 = Convert.ToString(c[1,1]);
            g2 = Convert.ToString(c[1,2]);
            g3 = Convert.ToString(c[1,3]);
            g4 = Convert.ToString(c[2,1]);
            g5 = Convert.ToString(c[2,2]);
            g6 = Convert.ToString(c[2,3]);
            g7 = Convert.ToString(c[3,1]);
            g8 = Convert.ToString(c[3,2]);
            g9 = Convert.ToString(c[3,3]);
            textBox19.Text = g1;
            textBox20.Text = g2;
            textBox21.Text = g3;
            textBox22.Text = g4;
            textBox23.Text = g5;
            textBox24.Text = g6;
            textBox25.Text = g7;
            textBox26.Text = g8;
            textBox27.Text = g9;

        }
    }
}




沒有留言:

張貼留言

Use google protocol buffers + QT +CMAKE

Protocol Buffers https://developers.google.com/protocol-buffers/ Serialize and ParseFrom https://www.jianshu....