有10个学生,每个学生的数据包括学号、姓名、三门课的成绩,从键盘输入学生数据,要求输出每个学生三门课程的平均成绩,以及最高分学生的数据(学号、姓名、三门课的成绩、该学生的平均成绩)
不知道哪里错了,无法正确进行输入输出
#include
struct Student{
int num;
char name[20];
float score[3];
float aver;
}stu[10];
int main(){
void input_aver(struct Student p[]);
void print_aver(struct Student p[]);
input_aver(stu);
print_aver(stu);
return 0;
}
void input_aver(struct Student p[]){
int i;
for(i=0;i<10;i++){
printf("请输入学号、姓名、三门课的成绩:\n");
scanf("%d%s%f%f%f\n",&p[i].num,p[i].name,&p[i].score[0],&p[i].score[1],&p[i].score[2]);
p[i].aver=(p[i].score[0]+p[i].score[1]+p[i].score[2])/3.0;
}
}
void print_aver(struct Student p[]){
int i,j;
int flag=0;
struct Student *k=p; //哪一位学生有最高分
float max=p[0].score[0];//放最高分
for(i=0;i<10;i++){
printf("No.%d的平均成绩为:%.2f\n",i+1,p[i].aver);
}
for(i=0;i<10;i++){
for(j=0;j<3;j++){
if(p[i].score[j]>max){
flag=1;
max=p[i].score[j];
}
}
if(flag)k=p+i;
}
printf("最高分的学生的学号、姓名、三门课成绩,平均成绩分别为:%d %s %.2f %.2f %.2f %.2f",
k->num,k->name,k->score[0],k->score[1],k->score[2],k->aver);
}
scanf里面的换行符 去掉
要求:
1、计算每个学生三门课的平均成绩,并输出。
2、求出平均分最高的学生数据,并输出。
(格式如下样例)
Input
第一行:N,表示N 个学生
下面N 行:每行数据包括学号、班级、姓名、三门课成绩。
Output
输出每个学生三门课的平均成绩,以及平均分最高分学生数据(包括学号、班级、姓名、三门课成绩,平均分)。
格式见下。(四舍五入保留一位小数)
Sample Input
4
20130008 tongxin1 wangmama 87 84 96
20130001 tongxin1 lanxin 92 84 83
20130007 tongxin2 wike 94 87 89
20130003 wulian4 tao 90 87 87
Sample Output
wangmama 89.0
lanxin 86.3
wike 90.0
tao 88.0
20130007 tongxin2 wike 94.0 87.0 89.0 90.0
#include <stdio.h>
struct student
{
char num[20][8];
char cla[20][20];
char name[20][20];
float a, b, c;
} student[20];
int main()
{
int N;
scanf("%d", &N);
int i;
for(i = 0; i < N; i++)
{
scanf("%s %s %s %f %f %f", &student[i].num, &student[i].cla, &student[i].name, &student[i].a, &student[i].b, &student[i].c);
}
float arr[20], max;
for(i = 0; i < N; i++)
{
arr[i] = (student[i].a + student[i].b + student[i].c) / 3;
printf("%s %.1f\n", student[i].name, arr[i]);
}
int k = 0;
max = arr[0];
for(i = 0; i < N; i++)
{
if(max < arr[i])
{
max = arr[i];
k = i;
}
}
printf("%s %s %s %.1f %.1f %.1f %.1f", student[k].num, student[k].cla, student[k].name, student[k].a, student[k].b, student[k].c, arr[k]);
return 0;
}
常规题目,就是有点麻烦