C语言程序 数据错误 PE?

   更新日期:2024.05.02
#include <stdio.h>
int main()
{
struct Student
{
long num;
char name[20];
int age;
float score[7];
float all_score;
float average;
} student[10];
int i=0,j=0,k=0;
for(i=0; i<10; i++)
{
scanf("%ld%s%d",&student[i].num,student[i].name,&student[i].age);
for(j=0; j< 7; j++)
scanf("%f",&student[i].score[j]);
student[i].all_score=0;
student[i].average=0;
}
for(i=0; i<10; i++)
{
for(j=0; j<7; j++)
student[i].all_score+=student[i].score[j];
student[i].average=student[i].all_score/7;
}
int J ;
for(i=0; i<10; i++)
{
if(student[i].all_score <student[i + 1].all_score)
k= i+ 1 ;
}
printf("%ld %s %d ",student[k].num,student[k].name,student[k].age);
for(j=0; j<7; j++)
printf("%.2f ",student[k].score[j]);
printf("%.2f %.2f\n",student[k].all_score,student[k].average);
return 0;
}

你可以参考一下:比较的是总成绩,不是平均成绩。排序的时候少了一个括号,并且通常结构体是写在函数外面的。

希望可以帮到你。

#include <stdio.h>
struct Student
{
long num;
char name[20];
int age;
float score[7];
float all_score;
float average;
} student[3];
int main()
{


int i = 0, j = 0, k = 0;
for (i = 0; i<10; i++)
{
scanf("%ld%s%d", &student[i].num, student[i].name, &student[i].age);
for (j = 0; j < 7; j++)
{
scanf("%f", &student[i].score[j]);
student[i].all_score += student[i].score[j];
}
student[i].average = student[i].all_score/7;
}

int  max = 0;
for (i = 0; i<10; i++)
if (student[max].all_score<student[i].average)
max = i ;
printf("%ld %s %d ", student[max].num, student[max].name, student[max].age);
for (j = 0; j<7; j++)
printf("%.2f ", student[max].score[j]);
//printf("%.2f %.2f
", student[max].all_score, student[max].average);
return 0;
}


PE不是格式错误吗...看看是不是没空格多个空格或者换行啥的

相关链接

欢迎反馈与建议,请联系电邮
2024 © 视觉网