班上有30名学生,每个记录包括学号、姓名、三门课程的成绩和三门课程平均成绩。从键盘输入学生的学号、姓名及三门课的成绩。打印三门课程平均成绩最高分的学生记录。实现计算和查找每门课的平均分、最低分、最高分。
#include <stdio.h>
#include <string.h>
struct stu
{
int a;
char b[10];
double c[3];
} stu[5];
int main()
{
printf("依次输入学号,姓名,三门成绩:\n");
int i, j;
double sum[5] = { 0 };
double max;
int t;
for (i = 0; i < 5; i++)
{
scanf("%d %s", &stu[i].a, stu[i].b);
for (j = 0; j < 3; j++)
{
scanf("%lf", &stu[i].c[j]);
sum[i] = sum[i] + stu[i].c[j];
}
}
max = sum[0];
for (i = 1; i < 5; i++)
{
if (sum[i] > max)
{
max = sum[i];
t = i;
}
}
printf("平均成绩最高分的学生记录:\n");
printf("%d ", stu[t].a);
printf("%s ", stu[t].b);
for (i = 0; i < 3; i++)
{
printf("%.lf ", stu[t].c[i]);
}
int d = 0, max1 = 0, min = 150, sum1[5] = { 0 };
float sum2 = 0,avg = 0;
printf("\n查询第几门课:\n");
scanf("%d", &d);
for (i = 0; i < 5; i++)
sum1[i] = stu[i].c[d-1], sum2 = sum2 + sum1[i];
avg = (sum2) / 5;
for (i = 0; i < 5; i++)
if (sum1[i] > max1)max1 = sum1[i];
for (i = 0; i < 5; i++)
if (sum1[i] < min)min = sum1[i];
printf("平均分为:%.2lf\n", avg);
printf("最高分为:%d\n", max1);
printf("最低分为:%d\n", min);
return 0;
}
#include <string.h>
struct stu
{
int a;
char b[10];
double c[3];
} stu[5];
int main()
{
printf("依次输入学号,姓名,三门成绩:\n");
int i, j;
double sum[5] = { 0 };
double max;
int t;
for (i = 0; i < 5; i++)
{
scanf("%d %s", &stu[i].a, stu[i].b);
for (j = 0; j < 3; j++)
{
scanf("%lf", &stu[i].c[j]);
sum[i] = sum[i] + stu[i].c[j];
}
}
max = sum[0];
for (i = 1; i < 5; i++)
{
if (sum[i] > max)
{
max = sum[i];
t = i;
}
}
printf("平均成绩最高分的学生记录:\n");
printf("%d ", stu[t].a);
printf("%s ", stu[t].b);
for (i = 0; i < 3; i++)
{
printf("%.lf ", stu[t].c[i]);
}
int d = 0, max1 = 0, min = 150, sum1[5] = { 0 };
float sum2 = 0,avg = 0;
printf("\n查询第几门课:\n");
scanf("%d", &d);
for (i = 0; i < 5; i++)
sum1[i] = stu[i].c[d-1], sum2 = sum2 + sum1[i];
avg = (sum2) / 5;
for (i = 0; i < 5; i++)
if (sum1[i] > max1)max1 = sum1[i];
for (i = 0; i < 5; i++)
if (sum1[i] < min)min = sum1[i];
printf("平均分为:%.2lf\n", avg);
printf("最高分为:%d\n", max1);
printf("最低分为:%d\n", min);
return 0;
}