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

首先设计如下界面:

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 aa

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button5_Click(object sender, EventArgs e)

        {

            double  x = Convert.ToDouble(textBox1 .Text );

            double  y = Convert.ToDouble (textBox2 .Text );

            double  result=Math.Pow (x,y);

            label3.Text = textBox1 .Text +“的”+textBox2 .Text +“次方为”+result ;

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            double x = Convert.ToDouble(textBox1.Text);

            double y = Convert.ToDouble(textBox2.Text);

            double result = x+y;

            label3.Text = textBox1.Text + “+” + textBox2.Text + “的值为” + result;

        }

 

        private void button2_Click(object sender, EventArgs e)

        {

            double x = Convert.ToDouble(textBox1.Text);

            double y = Convert.ToDouble(textBox2.Text);

            double result = x – y;

            label3.Text = textBox1.Text + “-“ + textBox2.Text + “的值为” + result;

        }

 

        private void button3_Click(object sender, EventArgs e)

        {

            double x = Convert.ToDouble(textBox1.Text);

            double y = Convert.ToDouble(textBox2.Text);

            double result = x * y;

            label3.Text = textBox1.Text + “*” + textBox2.Text + “的值为” + result;

        }

 

        private void button4_Click(object sender, EventArgs e)

        {

            double x = Convert.ToDouble(textBox1.Text);

            double y = Convert.ToDouble(textBox2.Text);

            double result = x /y;

            label3.Text = textBox1.Text + “/” + textBox2.Text + “的值为” + result;

        }

 

    }

}

 

运行结果:

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

来源:明子~

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年2月21日
下一篇 2019年2月21日

相关推荐