应该是交换数组元素那里错了,然后再用一个临时变量存储其中一个的值,然后在交换他们的值即可,修改如下:
#include <iostream>
using namespace std;
const int MAX_SIZE = 10;
int main(void){
int i,j,m,n;
int mat[MAX_SIZE+1][MAX_SIZE];
cout<<"Please input m,n:";
cin>>m>>n;
cout<<"Input array:\n";
for(i=0;i<m;i++){
for(j=0;j<n;j++){
cin>>mat[i][j];
}
}
int temp;
for(i=m-1;i>0;i--){
for(j=0;j<n;j++){
//交换两个变量的值,用一个临时变量存储其中一个的值,然后再交换它们的值即可
temp= mat[(i+1)%m][j];
mat[(i+1)%m][j] = mat[i][j] ;
mat[i][j] = temp;
}
}
for(i=0;i<m;i++){
for(j=0;j<n;j++){
cout<<mat[i][j]<<" ";
}
cout<<endl;
}
return 0;
}