Skip to content

Instantly share code, notes, and snippets.

@novnan
Created January 1, 2014 07:26
Show Gist options
  • Save novnan/8205876 to your computer and use it in GitHub Desktop.
Save novnan/8205876 to your computer and use it in GitHub Desktop.
// 某班有3名同学参加考试,求成绩最高的学生的姓名
#include <stdio.h>
#define N 3
void main()
{
char sName[N][10]; // 只写sName[N]为什么不行 // 假设姓名最多占10个字符(最多4个汉子或9个字母)
int i, t, iScore[N];
printf("顺序输入每个同学的姓名和成绩(用空格分开):\n");
for(i = 0; i < N; i++)
{
scanf("%s%d", sName[i], &iScore[i]); // sName[i]是与第i个同学的姓名对应的行地址,不是具体值,所以不用 &
}
t = 0; // t为最大值的下标
for(i = 1; i < N; i++)
{
if(iScore[i] > iScore[t]) t = i;
}
printf("%s的成绩最好,为%d\n", sName[t], iScore[t]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment