string[,] info = new string[8, 2] { { "吴松", "89" }, { "钱东宇", "90" }, { "伏晨", "98" }, { "陈陆", "56" }, { "周蕊", "60" }, { "林日鹏", "9" }, { "何昆", "93" }, { "关欣", "85" } };
int sum = 0;
string name;
for(int i=0;i<info.GetLongLength(0);i++){
if(sum<int.Parse(info[i,1])){
sum=int.Parse(info[i,1]);
name=info[i,0];
}
}
Console.Write("分数最高的是"+name+"分数是"+sum);
说错了 13版
我用10版运行了一下你的代码 错误说的是未给name赋初始值。我改成string name = " "; 以后运行成功了
for (int i = 0; i < info.GetLongLength(0); i++)
{
{
if (sum < int.Parse(info[i, 1]))
sum = int.Parse(info[i, 1]);
}
{
if (sum == int.Parse(info[i, 1]))
name = info[i, 0];
}
}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp1{ class Program { static void Main(string[] args) {//建立数组 string[] name = {"景珍", "林惠洋", "成蓉", "洪南昌", "龙玉民", "单江开", "田武山", "王三明"}; int[] score = {90,65,88,70,46,81,100,68}; int sum=0,avg;//总分sum,平均分avg for (int i = 0; i < score.Length; i++) { sum += score[i]; } avg = sum / score.Length; //Console.WriteLine(sum);//输出总分 Console.WriteLine("平均分是"+avg+"高于平均分的有:");//输出平均分 for (int a = 0; a < score.Length; a++) { if (score[a] > avg) { Console.Write(name[a]+" "); } } } }}