/*
输出最高成绩的信息
*/
#include<stdio.h>
struct xueSheng
{
int no;
char name[8];
int chengJi;
};
struct xueSheng maxScore(struct xueSheng s[], int len)
{
int i = 0,j = 0,k = 0;
for (i = 0; i<len; ++i)
{
if(k < s[i].chengJi)
{
k = s[i].chengJi;
j = i ;
}
}
return s[j];
}
int main()
{
struct xueSheng stu[] = {
{101, "小明", 60},
{102, "小李", 45},
{103, "小韩", 81},
{104, "小张", 97},
{105, "小路", 75}
};
struct xueSheng a = maxScore(stu,5);
printf("学号:%d,姓名:%s, 成绩:%d\n", a.no, a.name, a.chengJi );
return 0;
}
|
|