weixin_慕神6297684
2019-05-26 23:30
int i,dx;
string[] xm={"吴松","钱东宇","伏晨","陈陆","周薇","林日鹏","何昆","关欣"};
int[] cj = { 89, 90, 98, 56, 60, 91, 93, 85 };
dx = cj[0];
i = 0;
for (int k = 1; k < cj.Length; i++)
{
if (cj[k] > dx)
{
dx = cj[k];
i = k;
}
}
Console.WriteLine("分数最高的是{0},分数是{1}",xm[i],dx);
string[] name={"吴松","钱东宇","伏晨","陈陆","周蕊","林日鹏","何昆","关欣"};
int[] num={89,90,98,56,60,91,93,85};
int max=0;
int x=0;
for(int i=0;i<num.Length;i++)
{
if(max<num[i])
{
max=num[i];
x=i;
}
}
Console.Write("分数最高的是"+name[x]+",分数是"+num[x]);
string[,] s = { { "吴松", "89" }, { "钱东宇", "90" }, { "伏晨", "98" }, { "陈陆", "56" }, { "周蕊", "60" }, { "林日鹏", "91" }, { "钱东宇", "90" }, { "何昆", "93" }, { "关欣", "85" } };
int max = 0;
for (int i = 2; i <s.Length / 2 ; i++)
{
if (i==2) {
if (int.Parse(s[0, 1]) < int.Parse(s[1, 1])) {
max = int.Parse(s[1, 1]);
}
else {
max = int.Parse(s[i, 1]);
}
}
if (int.Parse(s[i, 1]) < max)
{
max = max;
}
else {
max = int.Parse(s[i, 1]);
}
}
string name ="";
for (int y = 0; y < s.Length / 2 ; y++) {
if (int.Parse(s[y, 1]) == max)
{
name = s[y, 0];
}
}
Console.WriteLine("分数最高的是"+name+","+"分数是"+max);
i++ 会超出数组长度.
i++,改成k++试试
C#开发轻松入门
254118 学习 · 1459 问题
相似问题