标签:ali ndt 应用 项目 box environ random http and
使用的语言:C#
基本思路:运用最近学习的C#窗体应用程序设计两个按钮一个显示的窗口,运用Random生成随机数,编写程序,调试运行。
窗体设计
代码
namespace 随机四则运算 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { Application.Exit(); } private void button1_Click(object sender, EventArgs e) { double x = Convert.ToDouble(1); double y = Convert.ToDouble(99); double z = Convert.ToDouble(30); richTextBox1.Text = ""; double [] a = new double [2*(int)z]; Random r = new Random(); for (int i = 0; i < 2*z; i++) { double temp = r.Next((int)x,(int)y); a[i] = temp; } for (int i = 0; i < z; i++) { double w = i % 3; string c = "+"; double d = a[i] + a[i + (int)z]; if (d <= (int)y / 2) c = "*"; if (d > (int)y / 2 && d <= (int)y) c = "+"; if (d > (int)y && d <= (int)y * 1.5) c = "/"; if (d > (int)y * 1.5 && d <= (int)y * 2 && a[i] > a[i + (int)z]) c = "-"; richTextBox1.AppendText(a[i].ToString() + (c) + a[i + (int)z].ToString() + ("=") + System.Environment.NewLine); } } } }
运行结果
标签:ali ndt 应用 项目 box environ random http and
原文地址:https://www.cnblogs.com/JL3Peanut/p/9770030.html