2010年10月1日 星期五

等差數列

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
    {
        Form1t newform;
        public Form1()
        {
            InitializeComponent();
        }
        private void label3_Click(object sender, EventArgs e)
        {
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //宣告
            int a1, an, n, d,sn;
            //輸入
            a1 = int.Parse(textBox1.Text);
            d = int.Parse(textBox2.Text);
            n=int.Parse(textBox3.Text);
            //處理
            an = a1 + (n-1) * d;
            sn = (a1 + an) * n / 2;
            //顯示
            textBox4.Text = "" + an;
            textBox5.Text = "" + sn;
        }
    
        private void button4_Click(object sender, EventArgs e)
        {
            newform = new Form1t();
            newform.Show();
        }
    }
}

沒有留言:

張貼留言