#include <stdio.h>
#define ROW 100
#define COL 100
int main(){
int row, col, matrix[ROW][COL];
int xx_row, sx_row, xx_col, sx_col;
int i, j;
scanf("%d %d", &row, &col);
for(i = 0; i < row; i++){
for(j = 0; j < col; j++){
scanf("%d",&(matrix[i][j]));
}
}
xx_row = 0;
sx_row = row-1;
xx_col = 0;
sx_col = col-1;
while( (xx_row <sx_row) || (xx_row<sx_row) ){
for(j = xx_col; j < sx_col; j++){
printf("%d\n", matrix[xx_row][j]);
}
for(i = xx_row; i < sx_row; i++){
printf("%d\n", matrix[i][sx_col]);
}
for(j = sx_col; j > xx_col; j--){
printf("%d\n", matrix[sx_row][j]);
}
for(i = sx_row; i > xx_row; i--){
printf("%d\n", matrix[i][xx_col]);
}
xx_row++;
sx_row--;
xx_col ++;
sx_col --;
}
system("pause");
return 0;
}
对于图片中的例子中间的不能输出,要怎么改
你难道想实现这样的效果?
还是想实现这样的效果?
以下代码实现的是第一种效果:
#include <stdio.h>
例子输入
4 4 1 2 3 412 13 14 511 16 15 610 9 8 7
例子输出
12345678910111213141516
但是这个只能对于行数和列数相同的可以,如果行数和列数不相同怎么办
还有这种情况?那我上机看看我的代码的执行:
===以下是 5行 8列的结果,输出也正常啊。。。
不信,你其实可以复制我写的代码,上机试试的。
(怎么有写好的代码你不复制,而要一个字一个字地输入?)
不单单是这一个例子的,就是这个程序只对于行数和列数相同的可以正常输出,如果不相同就会有一部分数据没有输出