实例2_4 算数运算符

时间:2022-10-13 21:08:24

题目描述 

设计一个C#Windows应用程序,进行算数运算符的应用测试。

实例2_4 算数运算符

操作步骤 

1>首先在Windows窗体中添加一个名为LblShow的Label控件。

2>在窗体设计区中双击空白区域,系统自动为窗体添加Load事件及对应的事件方法,然后在源代码视图中编辑代码。

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 Test2_4
{
    public partial class Test2_4 : Form
    {
        public Test2_4()
        {
            InitializeComponent();
        }

        private void lblShow_Click(object sender, EventArgs e)
        {
            int num1 = 5, num2 = 2;
            int a = num1 % num2;
            int b = num1 / num2;
            lblShow.Text = num1 + "%" + num2 + "=" + a;
            lblShow.Text += "\n" + num1 + "/" + num2 + "=" + b;
            a = num1++;
            b = --num2;
            lblShow.Text += "\n" + "a=num1++后,num1=" + num1 + ",a=" + a;
            lblShow.Text += "\n" + "b=--num2后,num2=" + num2 + ",b=" + b;
        }
    }
}