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

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

  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]+" " );
                }
            }
          
        }

正在回答

2 回答

<?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];
}


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

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();
        }
    }
}

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

举报

0/150
提交
取消

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

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