C语言程序 数据错误 PE?
发布网友
发布时间:2023-05-05 11:01
我来回答
共3个回答
热心网友
时间:2023-11-10 02:25
#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;
}
你可以参考一下:比较的是总成绩,不是平均成绩。排序的时候少了一个括号,并且通常结构体是写在函数外面的。
希望可以帮到你。
热心网友
时间:2023-11-10 02:25
#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\n", student[max].all_score, student[max].average);
return 0;
}
热心网友
时间:2023-11-10 02:26
PE不是格式错误吗...看看是不是没空格多个空格或者换行啥的
热心网友
时间:2023-11-10 02:25
#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;
}
你可以参考一下:比较的是总成绩,不是平均成绩。排序的时候少了一个括号,并且通常结构体是写在函数外面的。
希望可以帮到你。
热心网友
时间:2023-11-10 02:25
#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\n", student[max].all_score, student[max].average);
return 0;
}
热心网友
时间:2023-11-10 02:26
PE不是格式错误吗...看看是不是没空格多个空格或者换行啥的
热心网友
时间:2023-11-10 02:25
#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;
}
你可以参考一下:比较的是总成绩,不是平均成绩。排序的时候少了一个括号,并且通常结构体是写在函数外面的。
希望可以帮到你。
热心网友
时间:2023-11-10 02:26
#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\n", student[max].all_score, student[max].average);
return 0;
}
热心网友
时间:2023-11-10 02:26
PE不是格式错误吗...看看是不是没空格多个空格或者换行啥的