某班有5个学生,三门课。分别编写3个函数实现以下要求:
(1) 求各门课的平均分;
(2) 找出有两门以上不及格的学生,并输出其学号和不及格课程的成绩;
(3) 找出三门课平均成绩在85-90分的学生,并输出其学号和姓名

///main.m 文件 内容.
//
// main.m
// C8_练习
//
// Created by YIem on 15/11/19.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//

import <Foundation/Foundation.h>

import "MyFunc.h"

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


// 结构体数组
Stu dawa = {"大娃", 1 , 100, 100, 100};
Stu sanye = {"三爷", 2, 120, 120, 120};
Stu dasheng ={ "大剩", 3, 12, 34, 56};
Stu beta = {"β", 4, 60, 60, 60};
Stu marry = {"玛丽", 5, 100, 100, 300};
Stu s[5] = {dawa, sanye, dasheng, beta, marry};
// 1.
printf("Chinese: %.2f\n", avgByChinese(s, 5));
printf("Math: %.2f\nEnglish: %.2f\n", avgByMath(s, 5), avgByEnglish(s, 5));
// 2.

// 3.
findStu(s, 5);
// 4.
findStus(s, 5);
// 5.
findStua(s, 5);



return 0;

}



/// .h 文件里需要的内容

//
// MyFunc.h
// C8_练习
//
// Created by YIem on 15/11/19.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//

import <Foundation/Foundation.h>

// .h
struct stu {

char name[20];
int number;
float Chinese;
float Math;
float English;

};
typedef struct stu Stu;

/// 1. 平均分
/// 语文平均分
float avgByChinese(Stu s[], int count)
;
float avgByMath(Stu s[], int count);
float avgByEnglish(Stu s[], int count);
/// 3.
void findStu(Stu s[], int count);
/// 4.
void findStus(Stu s[], int count);

/// 5.
void findStua(Stu s[], int count);



///.m 文件需要的内容
//
// MyFunc.m
// C8_练习
//
// Created by YIem on 15/11/19.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//

import "MyFunc.h"

// .m
/// 1.平均分
/// 语文平均分
float avgByChinese(Stu s[], int count) {

// 保存平均分
float avg = 0;
for (int i = 0; i < count; i++) {
    // 吧所有的语文分都加和
    avg += s[i].Chinese;
    
}
// 求平均值
avg /= count;
return avg;

}
float avgByMath(Stu s[], int count) {

float avg = 0;
for (int i = 0; i < count; i++) {
    avg += s[i].Math;
}
avg /= count;
return avg;

}
float avgByEnglish(Stu s[], int count) {

float avg = 0;
for (int i = 0; i < count; i++) {
    avg += s[i].English;
}
avg /= count;
return avg;

}
/// 3.
void findStu(Stu s[], int count) {

for (int i = 0; i < count; i++) {
    // 临时变量
    Stu temp = s[i];
    // 平均分
    float avg = (temp.Chinese + temp.Math + temp.English) / 3;
    // 判断
    if (avg >= 100 && avg <= 200) {
        printf("%d %s\n", temp.number, temp.name);
    }
    
}

}
/// 4.
void findStus(Stu s[], int count) {

for (int i = 0; i < count; i++) {
    Stu t = s[i];
    float avg = (t.Chinese + t.Math);
    if (avg >= 100 && avg <= 200) {
        printf("%d %s %.2f\n", t.number, t.name, avg);
    }
}

}

/// 5.
void findStua(Stu s[], int count) {

for (int i = 0; i < count; i++) {
    Stu a = s[i];
    float avg = (a.Math + a.English) / 2;
    if (avg >= 100 && avg <= 200) {
        printf("%d %s %.2f\n", a.number, a.name, avg);
    }
}

}