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

希望能更优化下

string[,] scores = new string[8,2]{{"景珍","90"},{"林惠洋","65"},{"成蓉","88"},{"洪南昌","70"},{"龙玉民","46"},{"单江开","81"},{"田武山","100"},{"王三明","68"}};

          int avg=0;//平均分

            for(int i=0;i<scores.GetLongLength(0);i++){

                avg+=Convert.ToInt32(scores[i,1]);

            }

            avg = avg/8;

    

    string name ="";//高于平均分的名字

    for(int i=0;i<scores.GetLongLength(0);i++){

        if(Convert.ToInt32(scores[i,1])>=avg){

            name+=scores[i,0]+" ";

        }

   }

    name = name.Trim(' ');

    Console.WriteLine("平均分是{0},高于平均分的有:",avg);

    Console.WriteLine(name);


正在回答

1 回答

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

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

举报

0/150
提交
取消
C#开发轻松入门
  • 参与学习       254286    人
  • 解答问题       1459    个

本门课程是C#语言的入门教程,将带你轻松入门.NET开发

进入课程

希望能更优化下

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