C primer plus 第六版 第十章 第九题 编程练习答案

版权声明:转载请注明来源~ https://blog.csdn.net/Lth_1571138383/article/details/84847401

Github地址:φ(>ω<*)这里这里。

/*
    本程序应 习题-9 建立。
      题目要求: 编写一个程序,初始化一个double类型的3x5二维数组,使用一个处理变长数组的函数将其拷贝至另一个二维数组中。
                 还要编写一个以变长数组为形参的函数以显示两个数组的内容。这两个函数应该能处理任意NxM数组。
                 (如果编译器不支持变长数组,就使用传统C函数处理Nx5的数组。)
*/

#include<stdio.h>

#define I 3
#define O 5

void Cp(double (* a)[O], double (* b)[O]);

void Show(double  (* a)[O], double (* b)[O]);

int main(void)
{
	double a[I][O] = {};
	double b[I][O] = {};
	int y = 1;

	for (int c = 0; c < I; c++)
	{
		for (int d = 0; d < O; d++)
		{
			*(*(b+c) + d ) = y;
			y++;
		}
	}

	Cp(a, b);
	Show(a, b);

	printf("\nBye !\n");

	getchar();

	return 0;
}

void Cp(double  (* a)[O], double (* b)[O])
{
	for (int c = 0; c < I; c++)
	{
		for (int d = 0; d < O; d++)
		{
			*(*(a+c) + d ) = *(*(b+c) + d ) ;
		}
	}

	return;
}

void Show(double  (* a)[O], double (* b)[O])
{
	for (int c = 0; c < I; c++)
	{
		for (int d = 0; d < O; d++)
		{
			*(*(a+c) + d ) = *(*(b+c) + d ) ;
			printf("The array is : %lf.\n",  *(*(a+c) + d ) );
		}
	}

	return;
}

猜你喜欢

转载自blog.csdn.net/Lth_1571138383/article/details/84847401