#include <stdio.h>
/*
- 计算下全班所有学生的总成绩,平均成绩和60分以下的人数
*/
struct stu{
char *name;
int num;
int age;
char group;
float score;
}stus[]={
{“zhanagsan1”,5,18,‘1’,98.5},
{“zhanagsan2”,7,16,‘1’,98.5},
{“zhanagsan3”,12,28,‘1’,98.5},
{“zhanagsan4”,14,18,‘1’,98.5},
{“zhanagsan5”,10,18,‘1’,98.5}
};
int main(void)
{
//结构体数组的一个长度
int length = sizeof(stus) / sizeof(struct stu);
//计算总成绩、平均成绩、60分人数
average(stus,length);
return 0;
}
void average(struct stu *ps, int length){
int i;
int sum = 0;
int count = 0;//统计人数
for(i=0; i < length ; i++){
sum = sum + (ps + i)->score;
if((ps + i)->score < 60){
count++;
}
}
printf(“sum =%d average = %d count = %d\n”,
sum,sum/length,count);
}