文档库 最新最全的文档下载
当前位置:文档库 › 数组的基本操作

数组的基本操作

数组的基本操作
数组的基本操作

实验五数组的基本操作(2学时)

一、实验目的:

回顾c++语言中数组的定义和基本应用;

二、实验要求:

1.认真阅读和掌握本实验的程序。

2.上机运行本程序。

3.保存和打印出程序的运行结果,并结合程序进行分析。

三、实验内容:

有M个学生,学习N门课程,已知所有学生的各科成绩,

编程:分别求每个学生的平均成绩和每门课程的平均成绩。

四、注意事项:

1. 在磁盘上创建一个目录,专门用于存储数据结构实验的程序。

**参考程序:

#define M 5

#define N 4

#include "stdio.h"

main()

{ int i,j;

static float score[M+1][N+1]={{78,85,83,65}, {88,91,89,93}, {72,65,54,75},{86,88,75,60}, {69,60,50,72}};

for(i=0;i

{for(j=0;j

{ score[i][N] += score[i][j];

score[M][j] += score[i][j];

}

score[i][N] /= N;

}

for(j=0;j

score[M][j] /= M;

printf("学生编号课程1 课程2 课程3 课程4 个人平均\n"); for(i=0;i

{ printf("学生%d\t",i+1);

for(j=0;j

printf("%6.1f\t",score[i][j]);

printf("\n");

}

for(j=0;j<8*(N+2);j++)

printf("-");

printf("\n课程平均");

for(j=0;j

printf("%6.1f\t",score[M][j]);

printf("\n");

getchar();

}

相关文档