问答详情
源自:6-8 最终项目

大佬们,帮忙再优化下代码,谢谢

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

提问者:罪恶倾城 2018-09-18 08:05

个回答

  • 慕粉1542434494
    2018-10-19 13:25:31

    <?php
    $pop = ["景珍", "林惠洋",  "成蓉", "红南昌", "龙玉民", "单开江", "川武山", "王一鸣"];
    $score = [90,65,88,70,46,81,100,68];
    $sum = array_sum($score);
    $avg = $sum/conut($score);
    echo "平均分是".$avg;
    echo "高于平均分的有";
    $n = 0;
    for($i = 0;$i <count($score); $i++){
        if($score[$i] > $avg){
            $n = $i;
        }else{
            continue;
        }
        echo $pop[$i];
    }


  • 努力勤奋
    2018-09-29 15:15:40

    using System;

    namespace ConsoleApp3
    {
        class Program
        {
            static void Main(string[] args)
            {
                string[] name = new string[] {"景珍", "林惠洋",  "成蓉", "红南昌", "龙玉民", "单开江", "川武山", "王一鸣" };
                int[] score = new int[] { 90,65,88,70,46,81,100,68};
                int avg,sum=0;
                for (int i = 0; i < name.Length; i++)
                {
                    sum += score[i];
                }
                avg = sum / score.Length;
                Console.Write("平均分是" + avg+",");
                Console.WriteLine("高于平均分的有:");
                int n=0;
                for (int j = 0; j < score.Length; j++)
                {
                    if (score[j] > avg)
                        n = j;
                    else
                        continue;
                   
                    Console.Write(name[j]+"  ");
                }
            
                Console.ReadKey();
            }
        }
    }