A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 董立正 中级黑马   /  2015-12-5 10:51  /  702 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

#include <stdio.h>

void test(){
    struct Student{
        char name[20];
        int age;
    }boy[3]={{"sb",18},{"zbz",38},{"cgx",20}};
   
    struct Student girls[2] = {{"fengjie",18},{"cjk",28}};
   
    struct Student ds[2];
    ds[0] = (struct Student){"xzmly",18};
    ds[1] = (struct Student){"bdjy",18};
   
    struct Student stu[2];
    //stu[0].name = "zhangsan";
    //strcpy(stu[0].name,"zhangsan");
    scanf("%s",stu[0].name);
    stu[0].age = 19;
   
    //    char ch[0];
    //    scanf("%s",ch);
   
    for (int i = 0; i < 3; i++) {
        printf("name:%s,age:%d\n",boy[i].name,boy[i].age);
    }
}
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",'F',92.5},
        {104,"Cheng ling",'M',87},
        {105,"Wang ming",'M',58}
    };
    float sum = 0.0f;
    int count = 0;
    for (int i = 0; i < 5; i++) {
        sum += boy[i].score;
        if (boy[i].score < 60) {
            count++;
        }else if (boy[i].score >= 80 && boy[i].score <= 100){
            printf("name: %s, score: %.2f\n",boy[i].name,boy[i].score);
        }
            
    }
    printf("avgscore: %.2f\n",sum/5);
    printf("count: %d\n",count);
    return 0;
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马