程序填空题:找出多个学生中成绩最大者的下标。
有三个学生的信息(包括学号和成绩)保存在主函数的结构体中,主函数调用函数以找出多个学生中成绩最大者的下标。
c++
#include <stdio.h>
struct Student
{
char No[11];
int Score;
};
int FindMaxScore(struct Student stu[], int n);
int main(void)
{
struct Student stus[3] = {{"2008030201", 89}, {"2008030202", 92}, {"2008030203", 78}};
int k;
printf("%s %d\n", stus[k].No, stus[k].Score);
return 0;
}
int FindMaxScore()
{
int i, max, k=0;
max = stu[k].Score;
for (i=1; i<n; i++)
{
if ()
{
k = i;
max = stu[k].Score;
}
}
return k;
}
答案:
第1空:k = FindMaxScore(stus, 3);
第2空:struct Student stu[],int n
第3空:max < stu[k].Score
c++
#include <stdio.h>
struct Student
{
char No[11];
int Score;
};
int FindMaxScore(struct Student stu[], int n);
int main(void)
{
struct Student stus[3] = {{"2008030201", 89}, {"2008030202", 92}, {"2008030203", 78}};
int k;
printf("%s %d\n", stus[k].No, stus[k].Score);
return 0;
}
int FindMaxScore()
{
int i, max, k=0;
max = stu[k].Score;
for (i=1; i<n; i++)
{
if ()
{
k = i;
max = stu[k].Score;
}
}
return k;
}
答案:
第1空:k = FindMaxScore(stus, 3);
第2空:struct Student stu[],int n
第3空:max < stu[k].Score