其思路是用temp數組保存第壹行的數據,然後用最後壹行的數據覆蓋第壹行,最後將temp的數據賦給最後壹行,實現互換。
運行結果:
# include & ltstdio.h & gt
int main(){
int a[2][4]={
{1,2,3,4},
{5,6,7,8}
};
Printf("原始數組:\ n ");
for(int I = 0;我& lt2;i++){
for(int j = 0;j & lt4;j++){
printf("%d ",a[I][j]);
}
printf(" \ n ");
}
int temp[1][4]= { 0 };
for(int j = 0;j & lt4;j++){
temp[0][j]= a[0][j];
a[0][j]= a[1][j];
a[1][j]= temp[0][j];
}
Printf("新數組是:\ n ");
for(int I = 0;我& lt2;i++){
for(int j = 0;j & lt4;j++){
printf("%d ",a[I][j]);
}
printf(" \ n ");
}
}