希望能更優(yōu)化下
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);
2020-02-10
????????????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]+" ");
??????????????? }
??????????? }