码迷,mamicode.com
首页 > 编程语言 > 详细

用C++实现简单的生成随机数目的四则运算的题目的程序

时间:2018-10-07 18:50:47      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:c++实现   bubuko   http   随机数   com   temp   简单   ring   []   

        private void button1_Click(object sender, EventArgs e)
        {
            double n = Convert.ToDouble(textBox3.Text);
            double m = Convert.ToDouble(textBox2.Text);
            double q = Convert.ToDouble(textBox1.Text);
            richTextBox1.Text = "";
            double[] a = new double[2 * (int)q];
            Random r = new Random();
            for (int i = 0; i < 2 * q; i++)
            {
                double temp = r.Next((int)m, (int)n);
                a[i] = temp;
            }
            for (int i = 0; i < q; i++)
            {
                string c = "+";
                double b = a[i] + a[i + (int)q];
                if (b <= (int)n / 2)
                c = "*";
                if (b > (int)n / 2 && b <= (int)n)
                c = "+";
                if (b > (int)n && b <= (int)n * 1.5)
                c = "/";
                if (b > (int)n * 1.5 && b <= (int)n * 2 && a[i] > a[i + (int)q])
                c = "-";
                richTextBox1.AppendText(a[i].ToString() + (c) + a[i + (int)q].ToString() + ("=") + System.Environment.NewLine);
            }
        }
    }
}技术分享图片技术分享图片

用C++实现简单的生成随机数目的四则运算的题目的程序

标签:c++实现   bubuko   http   随机数   com   temp   简单   ring   []   

原文地址:https://www.cnblogs.com/lwan/p/9750806.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!