C语言程序改错(高分悬赏)

来源:百度知道 编辑:UC知道 时间:2024/05/10 04:58:32
按照如下格式定义一个结构体,并按照如下格式为一个班级的学生输入信息(不包括总分),通过公式“总分=数学+英语+政治”计算每个同学的总分,并按照降序排列,最后将其输出。
序号;姓名;数学;英语;政治;总分
num; name;math ;english;poli;total
长整型;字符串数组;实型;实型;实型;实型
根据题意编写程序。
下面的程序运行无误,但是只能循环一次。郁闷啊!!麻烦高手看看。
#include<stdio.h>
#include<stdlib.h>

struct student_type
{
unsigned long num;
char name[20];
float score[3];
float total;
}stud[5],t;

int main()
{
int i,j;
for(i=0; i<5; i++)
{
printf("please input the %dth num:",i+1);
scanf("%ld", &stud[i].num);
printf("please input the %dth name:",i+1);
scanf("%s", &stud[i].name);

for(j=0; j<3; j++)
{
printf("please input the %dth score:",j+1);
scanf("%f", &stud[i].score[j]);
}
printf("\n");
stud[i].total=0;
for(j=0; j<3; j++)
{
stud[i].tota

错误主要在:
(1)scanf("%s", &stud[i].name);把&去掉
(2)printf("score%f=%d ",j+1, stud[i].score[j]);格式控制出错
应该为printf("score%d=%f ",j+1, stud[i].score[j]);
其它的都很正确,认真点就可以了
#include<stdio.h>
#include<stdlib.h>

struct student_type
{
unsigned long num;
char name[20];
float score[3];
float total;
}stud[5],t;

int main()
{
int i,j;
for(i=0; i<5; i++)
{
printf("please input the %dth num:",i+1);
scanf("%ld", &stud[i].num);
printf("please input the %dth name:",i+1);
scanf("%s", stud[i].name);

for(j=0; j<3; j++)
{
printf("please input the %dth score:",j+1);
scanf("%f", &stud[i].score[j]);
}
printf("\n");
stud[i].total=0;
for(j=0; j<3; j++)
{