level 7
纯洁24888
楼主
/*
利用变长数组声明两个函数,函数copy()处理赋值元素到另一个数组,show_arr()现实两个数组的内容
*/
#include <stdio.h>
#define ROWS 2
#define COLS 3
void copy (int rows , int cols , int source [] [COLS] , int target [rows] [cols]);
int main (void)
{
int rows, cols;
int source [ROWS] [COLS] = { {1, 2, 3} , {4, 5, 6}};
int i , j;
int target [rows] [cols]; //变长数组
scanf ("%d %d" , &rows , &cols); //输入行列数,这里指定2 和 3
copy (rows , cols , source, target); //复制数组内容函数
for (i = 0; i < rows; i++)
for (j = 0; j < cols; j++)
printf ("\n%d " , source [0] [0]); //打印结果,结果错误!!!!
return 0;
}
void copy (int rows , int cols , int source [] [COLS] , int target [rows] [cols])
{
int i , j;
for (i = 0; i < rows; i++)
for (j = 0; j < cols; j++)
{
target [i] [j] = source [i] [j];
printf ("%d " , source [0] [0]);
} //未知错误!执行最后一次循环source首元素的值变成6
}



2015年12月24日 12点12分
1
利用变长数组声明两个函数,函数copy()处理赋值元素到另一个数组,show_arr()现实两个数组的内容
*/
#include <stdio.h>
#define ROWS 2
#define COLS 3
void copy (int rows , int cols , int source [] [COLS] , int target [rows] [cols]);
int main (void)
{
int rows, cols;
int source [ROWS] [COLS] = { {1, 2, 3} , {4, 5, 6}};
int i , j;
int target [rows] [cols]; //变长数组
scanf ("%d %d" , &rows , &cols); //输入行列数,这里指定2 和 3
copy (rows , cols , source, target); //复制数组内容函数
for (i = 0; i < rows; i++)
for (j = 0; j < cols; j++)
printf ("\n%d " , source [0] [0]); //打印结果,结果错误!!!!
return 0;
}
void copy (int rows , int cols , int source [] [COLS] , int target [rows] [cols])
{
int i , j;
for (i = 0; i < rows; i++)
for (j = 0; j < cols; j++)
{
target [i] [j] = source [i] [j];
printf ("%d " , source [0] [0]);
} //未知错误!执行最后一次循环source首元素的值变成6
}


