这样可行吗???
string[]name=new string{名字}; int[]sorce=new int[]{分数}; int max=0; int i=0; for(int x in sorce) { if(x>=max) { max=x; i++;}} Console.Write("分数最高为{0}"+name[i]+",分数是{1}"+sorce[i]); 这样可行吗???
string[]name=new string{名字}; int[]sorce=new int[]{分数}; int max=0; int i=0; for(int x in sorce) { if(x>=max) { max=x; i++;}} Console.Write("分数最高为{0}"+name[i]+",分数是{1}"+sorce[i]); 这样可行吗???
2015-12-18
string[]name=new string[]{"吴松","前东宇","伏晨","陈陆","周瑞","林日鹏","何坤","关欣"};
int[] sorce = new int[] { 89, 90, 98, 56, 60, 91, 93, 85 };
int max=sorce[0];
int y = 0; int x;//x为sorce数组的索引号,y为name数组的所以号
for(x=0;x<sorce.Length;x++)
{
if(sorce[x]>max)
{
max=sorce[x];
y=x;
}
}
Console.Write("分数最高的是{0}"+",分数是{1}",name[y],max);
//改成这样就对了,运行过了
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
class Program
{
static void Main(string[] args)
{
string []name={"吴松","钱东宇","伏晨","陈陆","周蕊","林日鹏","何昆","关欣"};
int []score={89,90,98,56,60,91,93,85};
int max=score[0];
string maxname=name[0];
for(int i=0;i<8;i++)
{
if(max<score[i])
{
max=score[i];
maxname=name[i];
}
}
Console.WriteLine("分数最高的是{0},分数是{1}",max,maxname);
}
}
}
举报