c - 二维数组反转

标签 c arrays function loops reverse

我正在尝试反转二维数组并且编译器工作正常,但数组仍然与开始时相同..

我在调用反向函数之前和之后打印数组,但似乎没有发生任何变化..
为什么?

代码如下:

#include<stdio.h>

void reverse(int table[ ][5]){
    int a,b,c,d;
    int temp = 0;
    for(a=0,c=3;a<=3;a++,c--){
        for(b=0,d=4;b<=4;b++,d--){
            temp = table[a][b];
            table[a][b]= table[c][d];
            table[c][d]= temp;      
        }
      }

    }

int main(int argc,char *argv[]){
    int i,j;
    int table[4][5];

    for(i=0;i<=3;i++){
       for(j=0;j<=4;j++){
          scanf("%d",&table[i][j]);
       }
    }

    for(i=0;i<=3;i++){
        for(j=0;j<=4;j++){
            printf(" %d",table[i][j]);
        }
    }
    printf("\n");

    reverse (table);


    for(i=0;i<=3;i++){
       for(j=0;j<=4;j++){
           printf("%d ",table[i][j]);
       }
    }

    return 0; 
    }

你能找到反向函数的问题吗??

最佳答案

问题是您要交换元素,然后再将它们交换回来。

关于c - 二维数组反转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12028468/

相关文章:

Javascript 按对象数组(复杂对象)分组

java - 为什么 0010 在 java 数组中给出不同的结果

python - 名称错误 : name 'mobile' is not defined

c - 我如何理解 typedef int (*ibm_ldap_search_s)(LDAP *, char *, int , char *, char * [],int , LDAPMessage **)

c - 在 C 中动态地从 3D 数组到 2D 数组

python - numpy.fftn 中哪些是高频项?

c - 将指针传递给嵌套函数

python - 为什么 "include"文件夹在 python 分发中包含 .h 文件(python 3.6.4)

c - 二维数组的 MPI_Scatter 和 malloc

c++ - 如何调用父类的函数?