003 计算某门功课的平均成绩

#include  <stdio.h>
//学生信息
typedef struct{
    char num[8];
    double score[2];
}STU;
//计算出第一门课程的平均分
double fun(STU std[],int n){
    int i;
    double sum = 0.0;
    for(i=0;i<n;i++){
        sum += std[i].score[0];
    }
    return sum/n;
}
void main()
{  STU  std[ ]={ "N1001", 76.5,82.0 ,"N1002", 66.5,73.0, 
              "N1005", 80.5,66.0,"N1006", 81.0,56.0 };
   printf("第1门课程的平均分是:%lf\n", fun(std,4) );
}

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

猜你喜欢

转载自blog.csdn.net/baidu_28916787/article/details/82155045
003