怎么把最好成績學生的姓名輸出在最后一句
string[] name = new string[5];//姓名數組
??????????? int[] num = new int[5];//分數數組
??????????? for (int i = 0; i < name.Length; i++)
??????????? {
??????????????? Console.Write("請輸入第" + (i + 1) + "位學生的姓名:");
??????????????? name[i] = Console.ReadLine();
??????????????? Console.Write("請輸入第" + (i + 1) + "位學生的分數:");
??????????????? num[i] = int.Parse(Console.ReadLine());
??????????? }
??????????? int max = num[0];
??????????? int ID = 0;
??????????? for (int i = 1; i < num.Length; i++)
??????????? {
??????????????? if(num[i]>max)
??????????????? {
??????????????????? max = num[i];
??????????????????? ID = i;
??????????????? }
??????????? }
??????????? Console.WriteLine("學生中成績最好的是" + max+"分,是第"+(ID+1)+"名學生,名字是"+ );
2016-05-11
string[] name = new string[3];//姓名數組
? ? ? ? ? ? int[] num = new int[3];//分數數組
? ? ? ? ? ? for (int i = 0; i < name.Length; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.Write("請輸入第" + (i + 1) + "位學生的姓名:");
? ? ? ? ? ? ? ? name[i] = Console.ReadLine();
? ? ? ? ? ? ? ? Console.Write("請輸入第" + (i + 1) + "位學生的分數:");
? ? ? ? ? ? ? ? num[i] = int.Parse(Console.ReadLine());
? ? ? ? ? ? }
? ? ? ? ? ? int max = num[0];
? ? ? ? ? ? int ID =0;
? ? ? ? ? ? for (int i = 1; i < num.Length; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (num[i] > max)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? max = num[i];
? ? ? ? ? ? ? ? ? ? ?ID = i;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine("學生中成績最好的是{0}分,是第{1}名同學,名字是{2}", max, ID + 1, name[ID]);