您是想询问关于C语言编程的问题吗?请提供具体的问题或需求,我会尽力帮助您解答。

2026-04-18 22:552阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计749个文字,预计阅读时间需要3分钟。

您是想询问关于C语言编程的问题吗?请提供具体的问题或需求,我会尽力帮助您解答。

由於今天在網上搜尋了一些c相關內容,以下是一些簡短的結論:

1. C語言是一種編程語言,以其效率和靈活性而聞名。

2.C語言常用于系統軟件開發,如操作系統和基礎軟件。

您是想询问关于C语言编程的问题吗?请提供具体的问题或需求,我会尽力帮助您解答。

3.C語言支持多種編程風格,從程式化到面向對象。

4.學習C語言對於理解後續的編程語言和技術非常重要。

5.C語言在嵌入式系統和遊戲開發中也非常常見。

由于今天在网上搜了一下c#写的计算器,发现大多都太繁琐了,很多没必要并且不容易理解的东西就专门写了这个博客

1.首先新建一个windows窗体应用的项目。执行文件-新建-项目-windows窗体应用

2.在工具箱中拖出一个textbox用于输入和显示,再拖出21个button按钮用来当计算器的按键,在textbox下面还有一个lable控件(我把它属性改成了空格所以看不到了),改一下按钮的text属性

3.双击数字按钮进入代码界面(数字只用一个事件即可,运算符也是用一个事件,其他每个按钮都需要双击添加事件)

4.代码呢已经准备好了,只要双击按钮进入代码界面,然后对应着粘上就行了(注意所有数字都是用的一个事件,都有标注,可以选择按钮,然后单击属性里的事件(闪电图标)查看click的事件)

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 计算器 { public partial class Form3 : Form { public Form3() { InitializeComponent(); } //定义变量 char oper; double num1; double num2; double result = 0; double memory=0.0; private void Button9_Click(object sender, EventArgs e)//数字按钮的功能实现 { Button a = (Button)sender;//判断按下的是哪个按钮 if (textBox1.Text == “0”) { textBox1.Text = a.Text; } else textBox1.Text += a.Text; }

private void Button16_Click(object sender, EventArgs e)//运算符按钮的功能实现 { if (textBox1.Text != "") { num1 = double.Parse(textBox1.Text); oper = char.Parse(((Button)sender).Text); textBox1.Text = ""; } } private void Button15_Click(object sender, EventArgs e)//C按钮的功能实现 { textBox1.Text = ""; textBox1.Focus(); num1 = 0; num2 = 0; oper = ' '; } private void Button14_Click(object sender, EventArgs e)//结果按钮的功能实现 { if (textBox1.Text != "") { num2 = double.Parse(textBox1.Text); switch (oper) { case '+': result = num1 + num2; break; case '-': result = num1 - num2; break; case '*': result = num1 * num2; break; case '÷': result = num1 / num2; break; } textBox1.Text = result.ToString(); } } private void Button17_Click(object sender, EventArgs e)//小数点按钮的功能实现 { if (textBox1.Text != "") { textBox1.Text += "."; } else { textBox1.Text = "0."; } } private void Button18_Click(object sender, EventArgs e)//M+按钮的功能实现 { if(textBox1.Text!="") { label1.Text = "M"; memory += double.Parse(textBox1.Text); textBox1.Text = " "; } } private void Button20_Click(object sender, EventArgs e)//MR按钮的功能实现 { textBox1.Text = memory.ToString(); } private void Button21_Click(object sender, EventArgs e)//MC按钮的功能实现 { label1.Text = ""; memory = 0; } private void Button19_Click(object sender, EventArgs e)//M-按钮的功能实现 { if (textBox1.Text != "") { label1.Text = "M"; memory -= double.Parse(textBox1.Text); textBox1.Text = " "; } } }

以上所述是小编给大家介绍的c#实现简易的计算器功能详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对易盾网络网站的支持!

本文共计749个文字,预计阅读时间需要3分钟。

您是想询问关于C语言编程的问题吗?请提供具体的问题或需求,我会尽力帮助您解答。

由於今天在網上搜尋了一些c相關內容,以下是一些簡短的結論:

1. C語言是一種編程語言,以其效率和靈活性而聞名。

2.C語言常用于系統軟件開發,如操作系統和基礎軟件。

您是想询问关于C语言编程的问题吗?请提供具体的问题或需求,我会尽力帮助您解答。

3.C語言支持多種編程風格,從程式化到面向對象。

4.學習C語言對於理解後續的編程語言和技術非常重要。

5.C語言在嵌入式系統和遊戲開發中也非常常見。

由于今天在网上搜了一下c#写的计算器,发现大多都太繁琐了,很多没必要并且不容易理解的东西就专门写了这个博客

1.首先新建一个windows窗体应用的项目。执行文件-新建-项目-windows窗体应用

2.在工具箱中拖出一个textbox用于输入和显示,再拖出21个button按钮用来当计算器的按键,在textbox下面还有一个lable控件(我把它属性改成了空格所以看不到了),改一下按钮的text属性

3.双击数字按钮进入代码界面(数字只用一个事件即可,运算符也是用一个事件,其他每个按钮都需要双击添加事件)

4.代码呢已经准备好了,只要双击按钮进入代码界面,然后对应着粘上就行了(注意所有数字都是用的一个事件,都有标注,可以选择按钮,然后单击属性里的事件(闪电图标)查看click的事件)

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 计算器 { public partial class Form3 : Form { public Form3() { InitializeComponent(); } //定义变量 char oper; double num1; double num2; double result = 0; double memory=0.0; private void Button9_Click(object sender, EventArgs e)//数字按钮的功能实现 { Button a = (Button)sender;//判断按下的是哪个按钮 if (textBox1.Text == “0”) { textBox1.Text = a.Text; } else textBox1.Text += a.Text; }

private void Button16_Click(object sender, EventArgs e)//运算符按钮的功能实现 { if (textBox1.Text != "") { num1 = double.Parse(textBox1.Text); oper = char.Parse(((Button)sender).Text); textBox1.Text = ""; } } private void Button15_Click(object sender, EventArgs e)//C按钮的功能实现 { textBox1.Text = ""; textBox1.Focus(); num1 = 0; num2 = 0; oper = ' '; } private void Button14_Click(object sender, EventArgs e)//结果按钮的功能实现 { if (textBox1.Text != "") { num2 = double.Parse(textBox1.Text); switch (oper) { case '+': result = num1 + num2; break; case '-': result = num1 - num2; break; case '*': result = num1 * num2; break; case '÷': result = num1 / num2; break; } textBox1.Text = result.ToString(); } } private void Button17_Click(object sender, EventArgs e)//小数点按钮的功能实现 { if (textBox1.Text != "") { textBox1.Text += "."; } else { textBox1.Text = "0."; } } private void Button18_Click(object sender, EventArgs e)//M+按钮的功能实现 { if(textBox1.Text!="") { label1.Text = "M"; memory += double.Parse(textBox1.Text); textBox1.Text = " "; } } private void Button20_Click(object sender, EventArgs e)//MR按钮的功能实现 { textBox1.Text = memory.ToString(); } private void Button21_Click(object sender, EventArgs e)//MC按钮的功能实现 { label1.Text = ""; memory = 0; } private void Button19_Click(object sender, EventArgs e)//M-按钮的功能实现 { if (textBox1.Text != "") { label1.Text = "M"; memory -= double.Parse(textBox1.Text); textBox1.Text = " "; } } }

以上所述是小编给大家介绍的c#实现简易的计算器功能详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对易盾网络网站的支持!