C编程问题,程序出错了,求大神解答,一下是我编写的,请各位大神帮帮忙
#include<stdio.h>#defineM45structstudent{intstuno;charname[20];floatscore[3];floatave...
#include<stdio.h>
#define M 45
struct student
{int stuno;
char name[20];
float score[3];
float average;
}
void input(struct student s[],int n)
{int i,j;
struct student t;
for(i=1;i<=n;i++)
{scanf("%d%s",&t.stuno,t.name);
for(j=0;j<=2;j++)
scanf("%f",&t.score[j]);
s[i]=t;
}
}
void caculate(struct student s[],int n)
{int i,j;
for(i=0;i<=n;i++)
s[i].average=0;
for(j=0;j<=2;j++)
s[0].score[j]=0;
for(i=1;i<=n;i++)
{for(j=0;j<=2;j++)
{s[i].average+=s[i].score[j];
s[0].score[j]+=s[i].score[j];
}
s[i].average/=3;
}
for(j=0;j<=2;j++)
s[0].score[j]/=n;
}
void output(struct student s[],int n)
{int i,j;
printf("stuno name score[0] score[1] score[2] average\n");
for(i=1;i<=n;i++)
{printf("%-5d%10s",s[i].stuno,s[i].name);
for(i=0;j<=2;j++)
printf("%6.1f",s[i].score[j]);
printf("%6.1f\n",s[i].average);
}
printf("average of total");
for(j=0;j<=2;j++)
printf("%6.1f",s[0].score[j]);
printf("\n");
}
void main()
{struct student stu[M];
int n;
printf("Please input the number of students(1-45)");
scanf("%d",&n);
input(stu,n);
caculate(stu,n);
output(stu,n);
} 展开
#define M 45
struct student
{int stuno;
char name[20];
float score[3];
float average;
}
void input(struct student s[],int n)
{int i,j;
struct student t;
for(i=1;i<=n;i++)
{scanf("%d%s",&t.stuno,t.name);
for(j=0;j<=2;j++)
scanf("%f",&t.score[j]);
s[i]=t;
}
}
void caculate(struct student s[],int n)
{int i,j;
for(i=0;i<=n;i++)
s[i].average=0;
for(j=0;j<=2;j++)
s[0].score[j]=0;
for(i=1;i<=n;i++)
{for(j=0;j<=2;j++)
{s[i].average+=s[i].score[j];
s[0].score[j]+=s[i].score[j];
}
s[i].average/=3;
}
for(j=0;j<=2;j++)
s[0].score[j]/=n;
}
void output(struct student s[],int n)
{int i,j;
printf("stuno name score[0] score[1] score[2] average\n");
for(i=1;i<=n;i++)
{printf("%-5d%10s",s[i].stuno,s[i].name);
for(i=0;j<=2;j++)
printf("%6.1f",s[i].score[j]);
printf("%6.1f\n",s[i].average);
}
printf("average of total");
for(j=0;j<=2;j++)
printf("%6.1f",s[0].score[j]);
printf("\n");
}
void main()
{struct student stu[M];
int n;
printf("Please input the number of students(1-45)");
scanf("%d",&n);
input(stu,n);
caculate(stu,n);
output(stu,n);
} 展开
展开全部
struct student
{int stuno;
char name[20];
float score[3];
float average;
};
加一个分号
{int stuno;
char name[20];
float score[3];
float average;
};
加一个分号
更多追问追答
追问
请问为什么我运行后会乱码?
追答
你的
void output(struct student s[],int n)
{int i,j;
printf("stuno name score[0] score[1] score[2] average\n");
for(i=1;i<=n;i++)
{printf("%-5d%10s",s[i].stuno,s[i].name);
for(j=0;j<=2;j++)// !!!这里错了
printf("%6.1f",s[i].score[j]);
printf("%6.1f\n",s[i].average);
}
printf("average of total");
for(j=0;j<=2;j++)
printf("%6.1f",s[0].score[j]);
printf("\n");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询