您的位置:首页 > 编程语言 > C语言/C++

C语言 数组长度...int length = sizeof(stu) / sizeof(stu[0]);

2016-01-02 00:41 381 查看
#include <stdio.h>

int main(int argc, const char * argv[])
{

struct Student {
int num;
char * name;
char sex;
float score;
};

struct Student stu[5] = {
{ 101, "Li ping", 'F', 45 },
{ 102, "Zhang ping", 'M', 62.5 },
{ 103, "He ping", 'F', 92.5 },
{ 104, "Cheng ping", 'M', 87 },
{ 105, "Wang ping", 'M', 58 }
};

int count = 0;
float sumScore = 0;
int length = sizeof(stu) / sizeof(stu[0]);
printf("%d\n", length);
for (int i = 0; i < length; i++) {
if (stu[i].score < 60.0) {
count++;
}
sumScore += stu[i].score;
}
printf("不及格人数 = %d , 平均分数是 %.2f\n", count,sumScore/length);

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: