⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2darray1.cpp

📁 c语言教程源码
💻 CPP
字号:
//这个程序在本书所带软盘中。文件名为2DARRAY1.CPP
//这个程序利用两维数组来存储和打印九九表。

#include <iostream.h>
#include <iomanip.h>

#define row 9
#define col 9

void main(void)
{
	void initialize(int[row][col]);		//定义一个带有两维数组参数的子程序
	void array_output(int[row][col]);	//定义显示两维数组的子程序

	int array[row][col];				//定义两维数组

	initialize(array);					//调用初始化子程序
	array_output(array);				//显示数组
}

/*******子程序initialize()**************/
void initialize(int int_array[row][col])
{
	cout << "现在利用两维数组存入九九表..." << endl;

	for(int i = 0; i < row; i++)
		for(int j = 0; j < col; j++)
			int_array[i][j] = (i+1)*(j+1);	//存入九九表
}

/**********子程序array_output()****************/
void array_output(int intarray[row][col])
{
	cout << setw(35) << "九九乘法表" << endl;
	for (int i = 0; i < row; i++) {		//外循环控制行数
		for (int j = 0; j < col; j++)	//内循环控制列数
			cout << setw(6) << intarray[i][j];
		cout << endl;
	}
}

/*这个程序运行后将显示如下运行结果:
现在利用两维数组存入九九表...
						九九乘法表
     1     2     3     4     5     6     7     8     9
     2     4     6     8    10    12    14    16    18
     3     6     9    12    15    18    21    24    27
     4     8    12    16    20    24    28    32    36
     5    10    15    20    25    30    35    40    45
     6    12    18    24    30    36    42    48    54
     7    14    21    28    35    42    49    56    63
     8    16    24    32    40    48    56    64    72
     9    18    27    36    45    54    63    72    81
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -