14.C语言基础完结篇

有一个班的5个学生,有3门课程。

1、求第一门课的平均分;

2、找出有两门以上课程不及格的学生,输出他们的学号和全部课程成绩及平均分

3、找出平均分在90分以上或全部课程成绩在85分以上的学生。 分别编写三个函数来实现以上三个要求

#include<stdio.h>

struct student
{
    char name[32];
    int hao;
    int score[3];
    
};

int AVGNUM(struct student *ps,int len)
{
    int sum = 0;
    int avg = 0;

    sum = ps[0].score[0] + ps[1].score[0] + ps[2].score[0] + ps[3].score[0] + ps[4].score[0];
    avg = sum / 5;

    printf("pinjun=%d\n",avg);

    return 0;
}

int GETSTU(struct student *ps,int len)
{
    int i = 0;
    int j = 0;
    int cnt = 0;
    int sum = 0;
    int avg = 0;

    for (i = 0; i < 5; i++)
    {
        cnt = 0;
        for (j = 0; j < 3; j++)
        {
            if (ps[i].score[j] < 60)
            {
                cnt++;
            }
        }
        if (cnt >= 2)
        {
            sum = ps[i].score[0] + ps[i].score[1] + ps[i].score[2];
            avg = sum / 3;
            printf("bujige2men:%d\na:%d\nb:%d\nc:%d\navg=%d\n",ps[i].hao,ps[i].score[0],ps[i].score[1],ps[i].score[2],avg);
        }
    }
    
    return 0;
}

int YOUXIU(struct student *ps,int len)
{
    int i = 0;
    int sum[5] = {0};
    int avg = 0;

    for (i = 0; i < 5; i++)
    {
        sum[i] = ps[i].score[0] + ps[i].score[1] + ps[i].score[2];
        avg = sum[i] / 3;

        if (avg > 90 || (ps[i].score[0] > 85 && ps[i].score[1] > 85 && ps[i].score[2] > 85))
        {
            printf("youxiu:%d\n",ps[i].hao);
        }
    }

    return 0;
}

int main()
{
    struct student s[5] = {{"zhang",1,{88,89,96}},{"li",2,{97,96,95}},{"wang",3,{83,66,58}},{"cheng",4,{55,66,33}},{"hu",5,{89,56,49}}};

    AVGNUM(s,5);
    GETSTU(s,5);
    YOUXIU(s,5);

    return 0;
}

  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值