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

最后一题,请问下,最后怎么输出 连着的 几个名字?

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

namespace projAboveAvg
{
    class Program
    {
        static void Main(string[] args)
        {
           
            string[] a =new string[8]{
                "景珍","林惠洋","成蓉","洪南昌","龙玉民","单江开","田武山","王三明"
            };
            int[] b = new int[8]{
                90,65,88,70,46,81,100,68
            };
            int i=0;
            int avge=0;
            int sum=0;
            int count=0;
       
            for(i=0;i<b.Length;i++){
                sum +=b[i];
                count=i+1;
                avge=sum/count;
            }
           for(i=0;i<b.Length;i++){
            if(b[i]<=avge){
                continue;
            }else{
                Console.WriteLine("平均分是"+avge+","+"高于平均分的有"+a[i]+"\t");
            }
          
           }
           
        }
    }
}


正在回答

3 回答

你这个步骤有一些是多余的。。。而且思路好像错了。。我把主要代码告诉你吧。

for(i=0;i<b.Length;i++){

    sum+=b[i];

}

avge=sum/b.Length;

Console.WriteLine("平均分是"+avge+","+"高于平均分的有");

for(i=0;i<b.Length;i++){

    if(b[i]>avge){

        Console.Write(a[i]+" ");

    }

}

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

qq_新生_11 提问者

感谢您!
2018-06-16 回复 有任何疑惑可以回复我~

最大值不应该是<么

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

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

            }
            //Console.Write("超过均分的有:" + seclect);
            Console.Write("平均分是{0}," + "高于平均分的有:{1}", avg, seclect);


            Console.ReadLine();


我这个行不?

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

举报

0/150
提交
取消

最后一题,请问下,最后怎么输出 连着的 几个名字?

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