程式設計工藝大師
加減乘除
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
float a = float.Parse(textBox1.Text), b = float.Parse(textBox2.Text);
label2.Text = (a + b).ToString();
}
private void button2_Click(object sender, EventArgs e)
{
float a = float.Parse(textBox1.Text), b = float.Parse(textBox2.Text);
label2.Text = (a - b).ToString();
}
private void button3_Click(object sender, EventArgs e)
{
float a = float.Parse(textBox1.Text), b = float.Parse(textBox2.Text);
label2.Text = (a * b).ToString();
}
private void button4_Click(object sender, EventArgs e)
{
float a = float.Parse(textBox1.Text), b = float.Parse(textBox2.Text);
if (b == 0)
{
label2.Text = "分母不能為零";
}
else
{
label2.Text = (a / b).ToString();
}
}
}
}
沒有留言:
張貼留言