求平均成绩


提交答案

分数: 3 (部分)
时间限制: 2.0s
内存限制: 64M

作者:
题目类型
允许的语言
C

问题描述

学生的记录由学号和成绩组成,NUMBER名学生的数据已在主函数中放入结构体数组stus中,请编写函数Average(),它的功能是:返回n名学生的平均成绩。

请将下列代码复制到程序提交区中,请勿改动main和Average()函数中的任何内容,仅在main()和Average()中填入所编写的若干变量定义或语句,完成功能。

#include <stdio.h>
#define  NUMBER  16
struct student{
   char num[10];
   int  score;
};
float Average(struct student *stu,int n){

    //请在此处填入所编写的函数Average()的实现代码,返回n名学生的平均成绩
    //此函数的代码要求必须使用指针的语法,不能使用数组的语法

}
int main ()
{
    double ave;
    struct student stus[NUMBER]={{"GA005",85}, {"GA003",76}, {"GA002",69},{"GA004",85},
                            {"GA001",91}, {"GA007",72}, {"GA008",64},{"GA006",87},
                            {"GA015",85}, {"GA013",91}, {"GA012",64},{"GA014",91},
                            {"GA011",77}, {"GA017",64}, {"GA018",64},{"GA016",72}}; 

   //请在此处填入调用函数Average()的代码,获得学生的平均成绩

   printf ("%.2f\n",ave);
   return 0;
}

输入格式

输出格式

学生的平均成绩(保留两位小数)。


评论


  • 0
    student  于 2024年9月16日 13:02 时评论

    include <stdio.h>

    define NUMBER 16

    struct student{ char num[10]; int score; }; float Average(Student *stus,int n){ float sum = 0.0; for(int i = 0;i<n;i++){ sum+=stus[i].score; } return sum/n; } int main () { struct student stus[NUMBER]={{"GA005",85}, {"GA003",76}, {"GA002",69},{"GA004",85}, {"GA001",91}, {"GA007",72}, {"GA008",64},{"GA006",87}, {"GA015",85}, {"GA013",91}, {"GA012",64},{"GA014",91}, {"GA011",77}, {"GA017",64}, {"GA018",64},{"GA016",72}};

    float ave = Average(stus,NUMBER); printf ("%.2f\n",ave); return 0; }


  • 0
    student  于 2024年9月16日 12:54 时评论

    include <stdio.h>

    define NUMBER 16

    struct student{ char num[10]; int score; }; float Average(struct student *stus,int n){ float sum = 0.0; for(int i = 0;i<n;i++){ sum+=stus[i].score; } return sum/n; //请在此处填入所编写的函数Average()的实现代码,返回n名学生的平均成绩 //此函数的代码要求必须使用指针的语法,不能使用数组的语法

    } int main () { struct student stus[NUMBER]={{"GA005",85}, {"GA003",76}, {"GA002",69},{"GA004",85}, {"GA001",91}, {"GA007",72}, {"GA008",64},{"GA006",87}, {"GA015",85}, {"GA013",91}, {"GA012",64},{"GA014",91}, {"GA011",77}, {"GA017",64}, {"GA018",64},{"GA016",72}};

    float ave = Average(stus,NUMBER); //请在此处填入调用函数Average()的代码,获得学生的平均成绩 printf ("%.2f\n",ave); return 0; }


  • 0
    student  于 2024年9月16日 12:50 时评论

    include <stdio.h>

    define NUMBER 16

    struct student{ char num[10]; int score; }; float Average(struct student stus[],int n){ float sum = 0.0; for(int i = 0;i<n;i++){ sum+=stus[i].score; } return sum/n; //请在此处填入所编写的函数Average()的实现代码,返回n名学生的平均成绩 //此函数的代码要求必须使用指针的语法,不能使用数组的语法

    } int main () { struct student stus[NUMBER]={{"GA005",85}, {"GA003",76}, {"GA002",69},{"GA004",85}, {"GA001",91}, {"GA007",72}, {"GA008",64},{"GA006",87}, {"GA015",85}, {"GA013",91}, {"GA012",64},{"GA014",91}, {"GA011",77}, {"GA017",64}, {"GA018",64},{"GA016",72}};

    float ave = Average(stus,NUMBER); //请在此处填入调用函数Average()的代码,获得学生的平均成绩 printf ("%.2f\n",ave); return 0; }