001 统计不及格学生的学号和人数

函数fun的功能:
1、在有n个元素的结构体中数组std中,查找不及格科目的学生,找到后输出学生的学号;
2、返回值是不及格科目的学生人数

#include<stdio.h>

//学生信息
typedef struct
{
    char num[8];      //学号
    double score[2];  //两门课的成绩
}STU;

//查找不及格科目的学生,找到学号,返回不及格科目学生人数
int fun(STU std[],int n){
    int i,k=0;
    for(i=0;i<n;i++){
        if(std[i].score[0]<60 || std[i].score[1]<60){
            k++;
            printf("学号:%s\n",std[i].num);
        }
    }
    return k;
}

void main(){
    STU std[4] = {"N1001", 76.5,82.0 ,"N1002", 53.5,73.0, "N1005", 80.5,66.0,"N1006", 81.0,56.0};
    printf("\n共有%d位学生有不及格科目\n",fun(std,4));
}

演示地址:https://tool.lu/coderunner/?id=5b1

猜你喜欢

转载自blog.csdn.net/baidu_28916787/article/details/82120215
001