第一题:
#include
#include
#define STUDENT_NUM 2 //学生数量,修改成10即可
#define COURSE_NUM 5 //课程数量,为5
typedef struct {
float course[COURSE_NUM];
float ave;
} student;
void main()
{
student st[STUDENT_NUM];
int i, j;
char item[10] = "cour1";
int h_st = 0, h_course = 0;
float course_average = 0.0;
for (i = 0; i < STUDENT_NUM; i++)
{
printf("Input score of student %d:n", i + 1);
st[i].ave = 0.0;
for (j = 0; j < COURSE_NUM; j++)
{
scanf("%f", &st[i].course[j]);
st[i].ave += st[i].course[j];
if (st[i].course[j] > st[h_st].course[h_course])
{
h_st = i;
h_course = j;
}
}
st[i].ave /= COURSE_NUM;
}
printf(" NO.t");
for (i = 0; i < COURSE_NUM; i++)
{
item[4] = i + '1';
printf("%st", item);
}
printf("aven");
for (i = 0; i < STUDENT_NUM; i++)
{
printf(" NO. %dt", i + 1);
for (j = 0; j < COURSE_NUM; j++)
printf("%.2ft", st[i].course[j]);
printf("%.2fn", st[i].ave);
}
printf("naverage: ");
for (i = 0; i < COURSE_NUM; i++)
{
course_average = 0.0;
for (j = 0; j < STUDENT_NUM; j++)
course_average += st[j].course[i];
course_average /= STUDENT_NUM;
printf("%.2ft", course_average);
}
printf("n");
printf("nhighest: %.2f NO. %d course %dnn", st[h_st].course[h_course], h_st + 1, h_course + 1);
}