C#设计一个简单计算器,实现两个数的加、减、乘、除、求幂等计算

设计一个简单计算器,实现两个数的加、减、乘、除、求幂等计算

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 _2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //加
        private void button1_Click(object sender, EventArgs e)
        {
            double a =Convert.ToDouble(txtA.Text);
            double b =Convert.ToDouble(txtB.Text);
            double s = a + b;
            lblShow.Text = a+"+"+b+"的值为:"+s;
        }
        //减
        private void button2_Click(object sender, EventArgs e)
        {
            double a = Convert.ToDouble(txtA.Text);
            double b = Convert.ToDouble(txtB.Text);
            double s = a - b;
            lblShow.Text = a + "-" + b + "的值为:" + s;
        }
        //乘
        private void button3_Click(object sender, EventArgs e)
        {
            double a = Convert.ToDouble(txtA.Text);
            double b = Convert.ToDouble(txtB.Text);
            double s = a * b;
            lblShow.Text = a + "*" + b + "的值为:" + s;
        }
        //除
        private void button4_Click(object sender, EventArgs e)
        {
            double a = Convert.ToDouble(txtA.Text);
            double b = Convert.ToDouble(txtB.Text);
            double s = a / b;
            lblShow.Text = a + "/" + b + "的值为:" + s;
        }
        //求幂
        private void button5_Click(object sender, EventArgs e)
        {
            double a = Convert.ToDouble(txtA.Text);
            double b = Convert.ToDouble(txtB.Text);
            lblShow.Text = a + "的" + b + "次方为:" ;
            lblShow.Text += Math.Pow(a, b);
        }
    }
}

测试结果:

C#设计一个简单计算器,实现两个数的加、减、乘、除、求幂等计算_第1张图片C#设计一个简单计算器,实现两个数的加、减、乘、除、求幂等计算_第2张图片

 C#设计一个简单计算器,实现两个数的加、减、乘、除、求幂等计算_第3张图片C#设计一个简单计算器,实现两个数的加、减、乘、除、求幂等计算_第4张图片C#设计一个简单计算器,实现两个数的加、减、乘、除、求幂等计算_第5张图片

 

 

 

 

你可能感兴趣的:(c#,开发语言)