#include <stdio.h>
struct student
{
int id;
char name[20];
float score;
}stu[3]={1001,"法外狂徒张三",97,1002,"李四",54,1003,"王五",65};
int main()
{
int i,max_score,tag=0;
max_score=stu[0].score;
for(i=0;i<3;i++)
{
if(stu[i].score>max_score)
{
max_score = stu[i].score;
tag=i;
}
}
printf("最高分的信息为:%d\t%s\t%3.2f\n",stu[tag].id,stu[tag].name,stu[tag].score);
//最低分
int min_score;
tag=0;
min_score = stu[0].score;
for(i=0;i<3;i++)
{
if(stu[i].score < min_score)
{
min_score = stu[i].score;
tag=i;
}
}
printf("最低分的信息为:%d\t%s\t%3.2f\n",stu[tag].id,stu[tag].name,stu[tag].score);
//平均分
float sum=0;
for(i=0;i<3;i++)
{
sum += stu[i].score;
}
printf("平均分为:%3.2f\n",sum/3);
//打印及格率
int jige=0;
float jigelv;
for(i=0;i<3;i++)
{
if(stu[i].score>60)
jige++;
}
jigelv = (float)jige/3*100;
printf("及格率为:%3.2f%%",jigelv);
return 0;
}
通过结构体数组求最大值,最小值,平均数和及格率
最新推荐文章于 2023-05-03 10:30:39 发布