#include <stdio.h> //https://www.renrendoc.com/paper/206978342.html //计算四位学生的平均成绩,保存在结构体中,然后列表输出这些学生信息 struct STUDENT { char name[16];int math;int english; int computer;float average; }; void getaverage(struct STUDENT *pst) { int sum=0; sum=sum+pst->math+pst->english+pst->computer; pst->average=sum/3.0; } main() { int i; struct STUDENT st[4]={{"AAAAA",99,98,97},{"BBBBB",96,95,94},{"CCCCC",93,92,91},{"DDDD",68,68,69}}; for(i=0;i<4;i++) getaverage(&st[i]); printf("NAME\tMath\tEnglish\tComputer\tAverage\n"); for(i=0;i<4;i++) printf("%s\t%d\t%d\t%d\t%d\n",st[i].name,st[i].math,st[i].english,st[i].computer,st[i].average); getchar(); }
#include <stdio.h> //https://www.renrendoc.com/paper/206978342.html //计算四位学生的平均成绩,保存在结构体中,然后列表输出这些学生信息 struct STUDENT { char name[16];int math;int english; int computer;float average; }; void getaverage(struct STUDENT *pst) { int sum=0; sum=sum+pst->math+pst->english+pst->computer; pst->average=sum/3.0; } main() { int i; struct STUDENT st[4]={{"AAAAA",99,98,97},{"BBBBB",96,95,94},{"CCCCC",93,92,91},{"DDDD",68,68,69}}; printf("NAME\tMath\tEnglish\tComputer\tAverage\n"); for(i=0;i<4;i++) {st[i].average=(st[i].math+st[i].english+st[i].computer)/3.0; printf("%s\t%d\t%d\t%d\t%f\n",st[i].name,st[i].math,st[i].english,st[i].computer,st[i].average); } getchar(); }
标签:struct,int,sum,C语言,STUDENT,填空,pst,结构 From: https://www.cnblogs.com/xkdn/p/17103292.html