为了账号安全,请及时绑定邮箱和手机立即绑定

表示不能接受,错哪喽?


        static void Main(string[] args)
        {
            string[]name=new string[]{"景珍","林慧洋","成蓉","洪南昌","龙玉民","单江开","田武山","王三明"};
            int[]num=new int[]{90,65,88,70,46,81,100,68};
            int sum=0;
            double avg;
            for(i=0;i<=num.Length;i++)
            {
                sum+=num[i];
            }
            avg=sum/num.Length;
            Console.WriteLine("平均分是"+avg+",高于平均分的有:");
            int index;
            for (a=0;a<=num.Length;a++)
            {
               if (num[a]>=avg)
                  {
                     index=a;
                     Console.Write(name[a]+" " );
                  }
            }
        }

正在回答

5 回答

加油,多练习一定可以。

0 回复 有任何疑惑可以回复我~

遍历数组时是for(int i=0;i<num.Length;i++)而不是i<=num.Length

0 回复 有任何疑惑可以回复我~

希望可以采纳。


0 回复 有任何疑惑可以回复我~

using System;
using System.Collections.Generic;
using System.Text;

namespace projAboveAvg
{
    class Program
    {




        static void Main(string[] args)
        {
            string[] name = new string[] { "景珍", "林慧洋", "成蓉", "洪南昌", "龙玉民", "单江开", "田武山", "王三明" };
            int[] num = new int[] { 90, 65, 88, 70, 46, 81, 100, 68 };
            int sum = 0;
            double avg;
            for (int i = 0; i <8; i++)
            {
                sum += num[i];
            }
            avg = sum /8;
            Console.WriteLine("平均分是" + avg + ",高于平均分的有:");
            int index;
            for (int a = 0; a <8; a++)
            {
                if (num[a] >= avg)
                {
                    index = a;
                    Console.Write(name[a] + " ");
                }
            }
        }

        }
    }

0 回复 有任何疑惑可以回复我~

引用变量前不加个$吗?我是小白。。。不喜勿喷

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

表示不能接受,错哪喽?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信