C++ Can';二维数组中的t开关列
如何在不使用函数等的情况下切换二维数组的列C++ Can';二维数组中的t开关列,c++,C++,如何在不使用函数等的情况下切换二维数组的列 #include <iostream> using namespace std; int main() { int arr[3][4]= { {1,2,3,4}, {5,6,7,8}, {6,4,5,3} }; cout << "Before change: "<<endl; for (int row=0;row<3;row++){ for (int col=0;col<4;co
#include <iostream>
using namespace std;
int main()
{
int arr[3][4]= {
{1,2,3,4},
{5,6,7,8},
{6,4,5,3}
};
cout << "Before change: "<<endl;
for (int row=0;row<3;row++){
for (int col=0;col<4;col++){
cout << arr[row][col]<<" ";
}
cout <<endl;
}
cout << "After the row change: "<<endl;
for (int row=2;row>=0;row--){
for(int col=0;col<4;col++){
cout<<arr[row][col]<<" ";
}
cout<<endl;
}
#包括
使用名称空间std;
int main()
{
int arr[3][4]={
{1,2,3,4},
{5,6,7,8},
{6,4,5,3}
};
基于“想交换第二列和第四列”的cout
要交换第2列和第4列,只需添加:
int temp;
for(int row=0;row<4;row++){
temp=arr[row][1];
arr[row][1]=arr[row][3];
arr[row][3]=temp;
}
int-temp;
对于(int row=0;row原始顺序
int ord [4] = { 0,1,2,3 }
更改订单
swap(ord[1], ord[2]);
cout << "After the row change: "<<endl;
for (int row=2;row>=0;row--){
for(int col=0;col<4;col++){
cout<<arr[row][ord[col]]<<" ";
}
cout<<endl;
}
swap(作战需求文件[1],作战需求文件[2]);
这里的切换是什么意思?只是打印或交换列?是的,我想交换第2列和第4列