c语言输入6名学生5门课程的成绩,写一个统计学生成绩的c语言程序,要求输入10个..._统计师_帮考网...

一、问题分析

需要保存6名学生5门功课的成绩,需要设计一个6行5列大小的二维数组scores[6][5]来存储30个成绩数据。保存6名学生的平均成绩,需要设计一个6列大小的一维数组来avgs[6]存储平均成绩。

为使程序具有更好的通用性,使用宏定义定义学生人数M和课程门数N。

计算每个学生的平均成绩时,累加该行所有列的成绩数据,并除以列大小即为该学生的平均成绩。

二、参考程序

#include #define M 6/* 学生人数 */

#define N 5/* 课程门数 */

/* 输入row个学生col门课程的成绩 */

void input(double scores[][N], int row, int col);

/* 计算row个学生的平均成绩并保存在avgs数组中 */

void average(double scores[][N], int row, int col, double avgs[]);

/* 输出所有学生的平均成绩 */

void output(double avgs[], int size);

void main()

{

double scores[M][N];

double avgs[M];

input(scores, M, N);

average(scores, M, N, avgs);

output(avgs, M);

}

/* 输入row个学生col门课程的成绩 */

void input(double scores[][N], int row, int col)

{

int i, j;

printf("请输入%d个学生%d门课程的成绩,每个学生成绩在一行,以空格分隔成绩:", row, col);

for(i=0; i{

for(j=0; j{

scanf("%lf", &scores[i][j]);

}

}

}

/* 计算row个学生的平均成绩并保存在avgs数组中 */

void average(double scores[][N], int row, int col, double avgs[])

{

int i, j;

for(i=0; i{

avgs[i] = 0.0;

for(j=0; j{

avgs[i] += scores[i][j];

}

avgs[i] /= col;

}

}

/* 输出所有学生的平均成绩 */

void output(double avgs[], int size)

{

int i;

printf("%6s%10s", "序号", "平均成绩");

printf("----------------------------");

for(i=0; i{

printf("%6d%10.2lf", i+1, avgs[i]);

}

}

三、运行测试

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值