int exchange(int a[3][3]) {int i,j; int b[3][3]; for(i=0;i<3;i++) for( j=0;j<3;j++) { int t; t=a[i][j]; b[j][i]=a[i][j]; a[i][j]=t; } for( i=0;i<3;i++) for( j=0;j<3;j++) printf("%d",b[i][j]); printf("\n"); return 0; }
为什么编译一直显示--------------------Configuration: 矩阵转置 - Win32 Debug-------------------- Compiling... 矩阵转置.cpp F:\矩阵转置.cpp(14) : error C2664: 'exchange' : cannot convert parameter 1 from 'int' to 'int [][3]' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast 执行 cl.exe 时出错. [解决办法] exchange(a[3][3]);改为exchange(a); [解决办法] 你的实参是一个数组元素,被调用函数的形参却是一个数组。 [解决办法]
int exchange(int a[3][3]) { int i,j; int b[3][3]; printf("%d %d %d\n%d %d %d\n%d %d %d\n",a[0][0],a[1][0],a[2][0],a[0][1],a[1][1],a[2][1],a[0][2],a[1][2],a[2][2]); return 0; }