P138-5 C语言源代码
#include <stdio.h> main() { struct student{ char no[8]; char name[8]; int ps; int sx; int qm; float zp; }; struct student ab[10]={ { "2020001","张三1",86,67,89,0 },{ "2020002","张三2",77,95,87,0 },{ "2020003","张三3",88,96,96,0 },{ "2020004","张三4",79,76,87,0 },{ "2020005","张三5",60,75,76,0 },{ "2020006","张三6",61,77,98,0 },{ "2020007","张三7",84,76,98,0 },{ "2020008","张三8",26,55,93,0 },{ "2020009","张三9",86,76,33,0 },{ "2020010","张三10",56,45,64,0 } }; int a,rs=0;float jgl; int len=sizeof(ab)/sizeof(ab[0]); for(a=0;a<len;a++) { ab[a].zp=ab[a].ps*0.3+ab[a].sx*0.3+ab[a].qm*0.4; if (ab[a].zp>=60) rs++; } jgl=(float)rs/len; for(a=0;a<len;a++) printf("学号:%s,姓名:%s,总评成绩为:%f\n",ab[a].no,ab[a].name,ab[a].zp); printf("及格人数为%d,及格率为%f",rs,jgl); getchar(); }