namespace WindowsApplication8
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {
            int[] a = new int[8];
            int b = 0;
            int c;
            int h = 0;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (b <= 7)
            {
                a[b] = Convert.ToInt32(textBox1.Text);
                b = b + 1;
            }
            else
            {
                for (int i = a.Length - 1; i >= 0; i--)
                {
                    for (int j = 0; j < i; j++)
                    {
                        if (a[j] > a[j + 1])
                        {
                            int k = a[j];
                            a[j] = a[j + 1];
                            a[j + 1] = k;
                        }
                    }
                }
                for (int j = 1; j < 7; j++)
                { 
                    h = h + a[j];
                }
                textBox1.Text = h.ToString;
            }
        }

解决方案 »

  1.   

    就算是个练习程序,你也不用这么玩吧,累不累啊,算了,最小改动吧namespace WindowsApplication8 

        public partial class Form1 : Form 
        { 
            public Form1() 
            { 
                InitializeComponent(); 
            }         int[] a;
            int b, c, h;
            private void Form1_Load(object sender, EventArgs e) 
            { 
                a = new int[8]; 
                b = 0; 
                h = 0; 
            } 
            private void button1_Click(object sender, EventArgs e) 
            { 
                if (b <= 7)
                {
                    a[b] = Convert.ToInt32(textBox1.Text);
                    b = b + 1;
                }
                else
                {
                    for (int i = a.Length - 1; i >= 0; i--)
                    {
                        for (int j = 0; j < i; j++)
                        {
                            if (a[j] > a[j + 1])
                            {
                                int k = a[j];
                                a[j] = a[j + 1];
                                a[j + 1] = k;
                            }
                        }
                    }
                    for (int j = 1; j < 7; j++)
                    {
                        h = h + a[j];
                    }
                    textBox1.Text = string.Format("{0:F2}", (double)h / 6);
                }
            } 
        }
    }