#include
struct student
{
int num;
char name[20];
float score;
}stu[4];
void fun1(float* max,struct student *p)//传址
{
int i;
*max=p->score ;
for(i=1;i<4;i++)
{
if(p->score >*max)
*max=p->score ;
p++;
}
}
void fun2(struct student stud[])//传值
{
int i;
float max=stud[0].score ;
for(i=1;i<4;i++)
if(stud[i].score >max)
max=stud[i].score ;
printf("最高分为:%f\n",max);
}
void main()
{
int i;
float max;
printf("请输入学生学号,姓名,和分数:\n");
for(i=0;i<4;i++)
scanf("%d%s%f",&stu[i].num ,&stu[i].name ,&stu[i].score );
printf("学号\t姓名\t分数\n");
for(i=0;i<4;i++)
printf("%d\t%s\t%f\n",stu[i].num ,stu[i].name ,stu[i].score );
fun1(&max,stu);
printf("最高分为:%f\n",max);
fun2(stu);
}
原程序错误已指出:有问题再联系
#include
struct student
{int num;
char name[20];
float score;
};stu[4];//此处应为: }stu[4];
void main()
{void print(struct student stu[]);
int i,k,max;
for(i=0;i<4;i++)
{printf("Plase input a student's No.,name and score:\n");
scanf("%d,%s,%f".&stu[i].num,stu[i].name,&stu[i].score);//此处用&stu[i].name
}
max=stu[0].score;
for(i=1;i<4;i++)
{if(stu[i].score>max)
{max=stu[i].score;k=i;}
}
print(stu[k]);//此处为:print(stu);
}
void print(struct student stu[])
{printf("The student who has the highest score is:\n");
printf("%d\n%s\n%f\n",stu[].num,stu[].name,stu[].score);
}
在你的基础上改的,你先看看,有问题再联系
#include
struct student
{
int num;
char name[20];
float score;
} ;
int main()
{
void max(struct student stu[]);
struct student stu[4];
int i;
for(i=0;i<4;i++)
{
printf("Plase input a student's No.,name and score,seperate by ' ':\n");
scanf("%d %s %f",&stu[i].num,stu[i].name,&stu[i].score);
}
max( stu );
return 0;
}
void max(struct student stu[])
{
int i,k=0,max;
max=stu[0].score;
for(i=1;i<4;i++)
{
if(stu[i].score>max)
{
max=stu[i].score;
k=i;
}
}
printf("The student who has the highest score is:\n");
printf("%d\n%s\n%f\n",stu[k].num,stu[k].name,stu[k].score);
}
不懂