我用二維數(shù)組做的(菜鳥(niǎo),勿噴)
string[,] str = new string[8, 2] { { "景珍", "90" }, { "林惠洋", "65" }, { "成蓉", "88" }, { "洪南昌", "70" }, { "龍玉民", "46" }, { "單江開(kāi)", "81" }, { "田武山", "100" }, { "王三明", "68" } };
? ? ? ? ? ? string name = "";
? ? ? ? ? ? int sum = 0,age;
? ? ? ? ? ? for (int i = 0; i < str.GetLength(0); i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? sum += int.Parse(str[i, 1]);
? ? ? ? ? ? }
? ? ? ? ? ? age = sum / str.GetLength(0);
? ? ? ? ? ? Console.WriteLine("平均分是" + age+ ",高于平均分的有:" + name);
? ? ? ? ? ? for (int k = 0; k < str.GetLength(0); k++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (int.Parse(str[k, 1]) > age)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? name = Convert.ToString(str[k, 0]);
? ? ? ? ? ? ? ? ? ? Console.Write(name+" ");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
2019-04-25
//我做得和你差不多
string[,] info = new string[8, 2] { { "景珍", "90" }, { "林惠洋", "65" }, { "成蓉", "88" }, { "洪南昌", "70" }, { "龍玉民", "46" }, { "單江開(kāi)", "81" }, { "田武山", "100" }, { "王三明", "68" } };
? ? ? ? ? ? int num = 0;
? ? ? ? ? ? int AVG = 0;
? ? ? ? ? ? for (int i = 0; i < info.GetLength(0); i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? num += int.Parse(info[i, 1]);
? ? ? ? ? ? }
? ? ? ? ? ? AVG = num / info.GetLength(0);
? ? ? ? ? ? Console.WriteLine("平均分是"+AVG+",高于平均分的有:");
? ? ? ? ? ? for (int j = 0; j < info.GetLength(0); j++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (int.Parse(info[j,1])>AVG)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.Write(info[j, 0]+" ");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }