试编写一个程序完成:有5个学生,每个学生的数据包括学号、姓名、3门课的成绩,从键盘输入5个学生数据,要
#include<stdio.h>#defineN5structstudent{charnum[6];charname[8];floatscore[3];floatavr...
#include<stdio.h>
#define N 5
struct student
{char num[6];
char name[8];
float score[3];
float avr;
}stu[N];
int main()
{int i,j,maxi;
float sum,max,average;
for(i=0;i<N;i++)
{
printf("input scores of student %d:\n",i+1);
printf("NO.:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{
printf("score %d:",j+1);
scanf("%f",&stu[i].score[j]);
}
}
average=0;
max=0;
maxi=0;
for(i=0;i<N;i++)
{
sum=0;
for(j=0;j<3;j++)
sum+=stu[i].score[j];
stu[i].avr=sum/3.0;
average=average+stu[i].avr;
if(sum>max)
{
max=sum;
maxi=i;
}
}
average/=N;
printf("NO. name score1 score2 score3 average\n");
for(i=0;i<N;i++)
{
printf("%5s%10s",stu[i].num,stu[i].name);
for(j=0;j<3;j++)
printf("%9.2f",stu[i].score[j]);
printf("%8.2f\n",stu[i].avr);
}
printf("average=%5.2f\n",average);
printf("最高分:学生 %s,%s\n",stu[maxi].num,stu[maxi].name);
printf("成绩:%6.2f,%6.2f,%6.2f,average:%5.2f.\n",stu[maxi],score[0],stu[maxi].score[1],stu[maxi].score[2],stu[maxi].avr);
return 0;
}
C:\Documents and Settings\Administrator\桌面\hj.c(39) : warning C4244: '=' : conversion from 'double ' to 'float ', possible loss of data
C:\Documents and Settings\Administrator\桌面\hj.c(62) : error C2065: 'score' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\hj.c(62) : error C2109: subscript requires array or pointer type
Error executing cl.exe.
hj.obj - 2 error(s), 1 warning(s)
我耗了一晚上也没找出错误在哪 下午要交报告 麻烦了 展开
#define N 5
struct student
{char num[6];
char name[8];
float score[3];
float avr;
}stu[N];
int main()
{int i,j,maxi;
float sum,max,average;
for(i=0;i<N;i++)
{
printf("input scores of student %d:\n",i+1);
printf("NO.:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{
printf("score %d:",j+1);
scanf("%f",&stu[i].score[j]);
}
}
average=0;
max=0;
maxi=0;
for(i=0;i<N;i++)
{
sum=0;
for(j=0;j<3;j++)
sum+=stu[i].score[j];
stu[i].avr=sum/3.0;
average=average+stu[i].avr;
if(sum>max)
{
max=sum;
maxi=i;
}
}
average/=N;
printf("NO. name score1 score2 score3 average\n");
for(i=0;i<N;i++)
{
printf("%5s%10s",stu[i].num,stu[i].name);
for(j=0;j<3;j++)
printf("%9.2f",stu[i].score[j]);
printf("%8.2f\n",stu[i].avr);
}
printf("average=%5.2f\n",average);
printf("最高分:学生 %s,%s\n",stu[maxi].num,stu[maxi].name);
printf("成绩:%6.2f,%6.2f,%6.2f,average:%5.2f.\n",stu[maxi],score[0],stu[maxi].score[1],stu[maxi].score[2],stu[maxi].avr);
return 0;
}
C:\Documents and Settings\Administrator\桌面\hj.c(39) : warning C4244: '=' : conversion from 'double ' to 'float ', possible loss of data
C:\Documents and Settings\Administrator\桌面\hj.c(62) : error C2065: 'score' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\hj.c(62) : error C2109: subscript requires array or pointer type
Error executing cl.exe.
hj.obj - 2 error(s), 1 warning(s)
我耗了一晚上也没找出错误在哪 下午要交报告 麻烦了 展开
展开全部
#include<stdio.h>
#define N 5
struct student
{char num[6];
char name[8];
float score[3];
float avr;
}stu[N];
int main()
{int i,j,maxi;
float sum,max,average;
for(i=0;i<N;i++)
{
printf("input scores of student %d:\n",i);
printf("NO.:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{
printf("score %d:",j);
scanf("%f",&stu[i].score[j]);
}
}
average=0;
max=0;
maxi=0;
for(i=0;i<N;i++)
{
sum=0;
for(j=0;j<3;j++)
sum+=stu[i].score[j];
stu[i].avr=sum/3;
average=average+stu[i].avr;
if(sum>max)
{
max=sum;
maxi=i;
}
}
average/=N;
printf("NO. name score1 score2 score3 average\n");
for(i=0;i<N;i++)
{
printf("%5s%10s",stu[i].num,stu[i].name);
for(j=0;j<3;j++)
printf("%9.2f",stu[i].score[j]);
printf("%8.2f\n",stu[i].avr);
}
printf("average=%5.2f\n",average);
printf("最高分:学生 %s,%s\n",stu[maxi].num,stu[maxi].name);
printf("成绩:%6.2f,%6.2f,%6.2f,average:%5.2f.\n",stu[maxi],stu[maxi].score[0],stu[maxi].score[1],stu[maxi].score[2],stu[maxi].avr);
return 0;
}
#define N 5
struct student
{char num[6];
char name[8];
float score[3];
float avr;
}stu[N];
int main()
{int i,j,maxi;
float sum,max,average;
for(i=0;i<N;i++)
{
printf("input scores of student %d:\n",i);
printf("NO.:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{
printf("score %d:",j);
scanf("%f",&stu[i].score[j]);
}
}
average=0;
max=0;
maxi=0;
for(i=0;i<N;i++)
{
sum=0;
for(j=0;j<3;j++)
sum+=stu[i].score[j];
stu[i].avr=sum/3;
average=average+stu[i].avr;
if(sum>max)
{
max=sum;
maxi=i;
}
}
average/=N;
printf("NO. name score1 score2 score3 average\n");
for(i=0;i<N;i++)
{
printf("%5s%10s",stu[i].num,stu[i].name);
for(j=0;j<3;j++)
printf("%9.2f",stu[i].score[j]);
printf("%8.2f\n",stu[i].avr);
}
printf("average=%5.2f\n",average);
printf("最高分:学生 %s,%s\n",stu[maxi].num,stu[maxi].name);
printf("成绩:%6.2f,%6.2f,%6.2f,average:%5.2f.\n",stu[maxi],stu[maxi].score[0],stu[maxi].score[1],stu[maxi].score[2],stu[maxi].avr);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
stu[maxi],score[0]
中间应该是个点,你用的逗号
/3.0改成/3
中间应该是个点,你用的逗号
/3.0改成/3
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
printf("成绩:%6.2f,%6.2f,%6.2f,average:%5.2f.\n",stu[maxi],score[0],stu[maxi].score[1],stu[maxi].score[2],stu[maxi].avr);
关键在这句,score[0] 前面打错了,应该是.而不是,
关键在这句,score[0] 前面打错了,应该是.而不是,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询