本帖最后由 Melody丶Zhy 于 2015-1-27 13:08 编辑
直接上代,题目要求是输出5名学生中最高分学生的信息,最后的输出格式是 学号:*** 姓名:*** 分数:****,我这个输出不是最高分,不知道怎么改了。。还有2个警告。。 len = sizeof(s)/sizeof(s[0]);struct students maxScore(struct students s[], int len);- #include<stdio.h>
- struct students{
- int no;
- char name[7];
- int score;
- };
- struct students maxScore(struct students s[], int len)
- {
- int i = 0,maxScore = 0,j;
- len = sizeof(s)/sizeof(s[0]);
- for (i = 0; i<len; ++i){
- if(maxScore<s[i].score){
- maxScore = s[i].score;
- j = i ;
- }
-
- }
- return s[j];
- }
- int main()
- {
-
- struct students stu[] = {{14001, "张三", 60},
- {14002, "李四", 45},
- {14003, "张思", 81},
- {14004, "李武", 97},
- {14005, "张武", 75}};
-
- struct students a = maxScore(stu,5);
-
- printf("学号:%d,姓名:%s, 成绩:%d", a.no, a.name, a.score );
- return 0;
- }
复制代码
|