1. 程式人生 > >輸出四則運算

輸出四則運算

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 _1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
       
        
        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  d=a[i]+a[i+(int)q];
                if (d <= (int)n/2)
                    c = "*";
                if (d > (int)n / 2 && d <= (int)n)
                    c = "+";
                if (d > (int)n && d <= (int)n*1.5)
                    c = "/";
                if (d > (int)n * 1.5 && d <= (int)n*2 && a[i] > a[i + (int)q])
                    c = "-";  
                richTextBox1.AppendText(a[i].ToString() + (c) + a[i + (int)q].ToString() + ("=")+System .Environment .NewLine );             }               }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
          
        }         private void Form1_Load(object sender, EventArgs e)
        {         }         private void label3_Click(object sender, EventArgs e)
        {         }         private void label2_Click(object sender, EventArgs e)
        {         }         private void textBox2_TextChanged(object sender, EventArgs e)
        {         }         private void textBox1_TextChanged_1(object sender, EventArgs e)
        {         }         private void textBox3_TextChanged(object sender, EventArgs e)
        {         }     }
}