求某学生8门课的平均分

某学生的记录由学号、8门课成绩和平均分组成,学号和8门课成绩在主函数中给出。编写fun函数,功能是:求出该学生的平均分放在ave成员中。函数中的参数由学生自己给出。

函数接口定义:

void fun();

fun函数功能是:求出该学生的平均分放在ave成员中。函数中的参数由学生自己给出。

裁判测试程序样例:

#include <stdio.h>
#define N 8
struct student
{
char num[10];
float a[N];
float ave;
};
void fun();
int main()
{
struct student s={“007”,89.5,98.0,67.5,88.0,90,77,79,97};
int i;
fun(&s);
printf(“The %s’s student data:\n”,s.num);
for(i=0;i<N;i++)
printf("%4.1f\n",s.a[i]);
printf(“ave=%7.2f\n”,s.ave);
return 0;
}

/* 请在这里填写答案 */

输出样例:

The 007’s student data:
89.5
98.0
67.5
88.0
90.0
77.0
79.0
97.0
ave= 85.75

fun 函数:

void fun(struct student *s)
{
float t;
for(int i=0;i<8;i++)
{
t+=s->a[i];
}
s->ave = t/8;
}

发布了13 篇原创文章 · 获赞 5 · 访问量 757

猜你喜欢

转载自blog.csdn.net/TWRenHao/article/details/103501448
今日推荐