8.编写一个程序,初始化一个3x5的二维double数组,并利用一个基于变长数组的函数把该数组复制到另一个二维数组。还要编写。个基于变长数组的函数来显示两个数组的内容。这两个函数应该能够处理任意的NxM数组(如果没有可以支持变长数组的编译器,就使用传统C中处理Nx5数组的函数方法)。
# include <stdio.h>
void copy_ptr(double *array, double *target, int var);
void show_ptr(double (*array)[5], double (*target)[5], int rows, int clos);
int main(void)
{
double array[3][5] = {
{1,2,3,4,5},
{2,4,6,8,10},
{1,3,5,7,9},
};
double target[3][5] = {0};
copy_ptr(array[0], target[0], 15);
show_ptr(array, target, 3, 5);
return 0;
}
void copy_ptr(double *array, double *target, int var1)
{
for(int i = 0; i < var1; i++)
{
target[i] = array[i];
}
}
void show_ptr(double (*array)[5], double (*target)[5], int rows, int clos)
{
int i, j;
printf("array:\n");
for(i = 0; i < rows; i++)
{
for(j = 0; j < clos; j++)
printf("%.1lf ", array[i][j]);
printf("\n");
}
printf("target:\n");
for(i = 0; i < rows; i++)
{
for(j = 0; j < clos; j++)
printf("%.1lf ", target[i][j]);
printf("\n");
}
}