Created
January 1, 2014 07:26
-
-
Save novnan/8205876 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 某班有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