编程序:
已知学生记录由学号和成绩组成,其类型定义如下所示:
struct student
{char no[10];float score;}
编写程序输入N个学生的数据,然后输出分数最高的学生数据,以及分数最高的学生人数。注意:分数最高的学生可能不止一个。
#include<stdio.h>
#include<stdlib.h>
struct student
{
char no[10];
float score;
};
main()
{
int i,N,count=0;
float max;
struct student *p;
printf("please input students'number:N=");
scanf("%d",&N);
p=(struct student*)malloc(N*sizeof(struct student));
printf("\nplease input students' score:\n");
printf("NO.\tscore\n");
for(i=0;i<N;i++)
{
scanf("%s %f",(p+i)->no,&(p+i)->score);
if(i==0)max=p->score;
else if(max<(p+i)->score)max=(p+i)->score;
}
printf("\nstudents of max score:\nNO.\tscore\n");
for(i=0;i<N;i++)
{
if(max==(p+i)->score)
printf("%s\t%.2f\n",(p+i)->no,(p+i)->score),count++;
}
printf("\nmax \ttotal\n");
printf("%.2f\t%d\n",max,count);
free(p);
} /*刚刚有点小问题,改过来了,望采纳*/