问题1.思考实现?
struct stu
{
int num;
char *name;
char sex;
float score;
};
struct stu boy[5] ={
{101,"Li ping",'F',45};
{102,"Zhang ping",'M',62.5};
{103,"He fang",'F',92.5};
{104,"Cheng ling",'M',87};
{105,"Wang ming",'M',58};
};
问:利用上面的结构体计算学生的平均成绩和不及格的人数?
打印80~100分学生的成绩及姓名?
代码实现:#include <stdio.h>
int main(int argc,const char * argv[])
{
struct stu
{
int num;
char *name;
char sex;
float score;
}
struct stu boy[5] =
{
{101,"Li ping",'F',45},
{102,"Zhang ping",'M',62.5},
{103,"He fang",'M',92.5},
{104,"Cheng ling",'M',87},
{105,"Wang ming",'M',58},
};
float num = 0;
int count = 0;
for(int i = 0;i < 5;i++)
{
sum+=boy[5].score;
if(boy[i] < 60)
{
count ++;
}
if(boy[i] > =80&&boy[i] <=100)
{
printf("name:%s\nscore:%.2f\n",boy[i].name,boy[i].score);
}
}
return 0;
}
|
|