2010年10月22日 星期五

10/22

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[] TextBoxs;
        int[,] a = new int[4, 4];
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            Buttons = new System.Windows.Forms.Button[9];
            TextBoxs = new System.Windows.Forms.TextBox[9];

            for (int j = 0; j < 9; ++j)
            {
                TextBoxs[j] = new TextBox();
                this.Controls.Add(TextBoxs[j]);
                if (j <= 2)
                    TextBoxs[j].Location = new System.Drawing.Point(10 + j * 100, 10);
                else if (j > 2 && j <= 5)
                    TextBoxs[j].Location = new System.Drawing.Point(10 + (j - 3) * 100, 40);
                else if (j > 5 && j <= 9)
                    TextBoxs[j].Location = new System.Drawing.Point(10 + (j - 6) * 100, 70);
            }
            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 * 100, 10+100);
                else if (i > 2 && i <= 5)
                    Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 100, 40+100);
                else if (i > 5 && i <= 9)
                    Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 100, 70+100);
            }
            TextBoxs[0].Text = "7";
            TextBoxs[1].Text = "2";
            TextBoxs[2].Text = "4";
            TextBoxs[3].Text = "5";
            TextBoxs[4].Text = "0";
            TextBoxs[5].Text = "6";
            TextBoxs[6].Text = "8";
            TextBoxs[7].Text = "3";
            TextBoxs[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());
            int i = sender.ToString().Length;
            MessageBox.Show("" + sender.ToString().Substring(i - 1));

        }
        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 9; i++)
            {
                if (i <= 2)
                    a[1, i + 1] = Convert.ToInt16(TextBoxs[i].Text);
                else if (i >= 3 && i <=5 )
                    a[2, i - 2] = Convert.ToInt16(TextBoxs[i].Text);
                else if (i >= 6 && i <= 9)
                    a[3, i - 5] = Convert.ToInt16(TextBoxs[i].Text);
            }
            for (int i = 0; i < 9; i++)
            {
                if (i <= 2)
                    Buttons[i].Text = Convert.ToString(a[1, i + 1]);
                else if (i >= 3 && i <=5 )
                    Buttons[i].Text = Convert.ToString(a[2, i - 2]);
                else if (i >= 6 && i <= 9)
                    Buttons[i].Text = Convert.ToString(a[3, i - 5]);
            }
                    }
        }
    }

2010年10月8日 星期五

99乘法表

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 Form1t : Form
    {
        public Form1t()
        {
            InitializeComponent();
        }
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
        private void button2_Click(object sender, EventArgs e)
        {
            {
            int sum = 0;
            int[,] arr2 = new int[10, 10];
            for (int i = 1; i <= 9; i++)
                for (int j = 1; j <= 9; j++)
                {
                    sum = i * j;
                    arr2[i, j] = sum;
                }
            for (int i = 1; i <= 9; i++)
                {
                    listBox1.Items.Add(+i + "*" + 1 + "=" + arr2[i, 1]+"," +i + "*" + 2 + "=" + arr2[i, 2]
                        + "," + i + "*" + 3 + "=" + arr2[i, 3] + "," + i + "*" + 4 + "=" + arr2[i, 4]
                        + "," + i + "*" + 5 + "=" + arr2[i, 5] + "," + i + "*" + 6 + "=" + arr2[i, 6]
                        + "," + i + "*" + 7 + "=" + arr2[i, 7] + "," + i + "*" + 8 + "=" + arr2[i, 8]
                        + "," + i + "*" + 9 + "=" + arr2[i, 9]);
                }
        }
       
        }
    }
}

3*3矩陣運算

            int[,] a = new int[4,4];
            int[,] b = new int[4,4];
            int[,] c = new int[4,4];
            String c1, c2, c3, c4, c5, c6, c7, c8, c9;
            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];
            c1 = Convert.ToString(c[1, 1]);
            c2 = Convert.ToString(c[1, 2]);
            c3 = Convert.ToString(c[1, 3]);
            c4 = Convert.ToString(c[2, 1]);
            c5 = Convert.ToString(c[2, 2]);
            c6 = Convert.ToString(c[2, 3]);
            c7 = Convert.ToString(c[3, 1]);
            c8 = Convert.ToString(c[3, 2]);
            c9 = Convert.ToString(c[3, 3]);
            textBox19.Text = c1;
            textBox20.Text = c2;
            textBox21.Text = c3;
            textBox22.Text = c4;
            textBox23.Text = c5;
            textBox24.Text = c6;
            textBox25.Text = c7;
            textBox26.Text = c8;
            textBox27.Text = c9;

2010年9月24日 星期五

99乘法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int sum = 0;
            int sum2 = 0;
            int[] arr1 = new int[10];
            int[,] arr2 = new int[10,10];
            for (int i = 1; i <= 9; i++)
            {
                sum = sum + i;
                for (int j = 1; j <= 9; j++)
                {
                    sum2 = sum2 + j;
                    arr2[i, j] = i * j;
                    Console.WriteLine(+i+"*"+j+"="+arr2[i,j]);
                   
                }
            }
        }
    }
}

2010年9月17日 星期五

1~100總和

#include<stdio.h>
#include<conio.h>
int main()
{
    int i;
    int sum=0;
    for( i=1; i<=100; i++)
    {
    sum=sum+i;
    }
    printf("%d\n",sum);
    getch();   
    return 0;  
}