Form1.cs
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 button1_Click(object sender, EventArgs e)
{
//宣告
int a1, an, d, n, sn;
//輸入
a1 = int.Parse(textBox1.Text);
d = int.Parse(textBox2.Text);
n = int.Parse(textBox3.Text);
//計算
an = a1 + (n - 1) * d;
sn = n * (a1 + an) / 2;
//Post
textBox4.Text = "" + an;
textBox5.Text = "" + sn;
}
private void button2_Click(object sender, EventArgs e)
{
int sum = 0;
int[,] arr1 = new int[99, 99];
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
sum = i * j;
arr1[i, j] = sum;
}
}
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
Console.WriteLine("" + i + "*" + "" + j + "=" + arr1[i, j]);
Console.WriteLine("i=" + i + "j= " + j);
listBox1.Items.Add("" + i + "*" + "" + j + "=" + arr1[i, j]);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
newform = new Form2();
newform.Show();
}
}
}
==========================================================================
Form2.cs
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 button3_Click(object sender, EventArgs e)
{
int sum = 0;
int[,] arr1 = new int[99, 99];
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
sum = i * j;
arr1[i, j] = sum;
}
}
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
Console.WriteLine("" + i + "*" + "" + j + "=" + arr1[i, j]);
Console.WriteLine("i=" + i + "j= " + j);
listBox1.Items.Add("" + i + "*" + "" + j + "=" + arr1[i, j]);
}
}
}
}
}
沒有留言:
張貼留言