大佬們,幫忙再優(yōu)化下代碼,謝謝
? 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-10-19
2018-09-29
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();
??????? }
??? }
}