- #1
magnifik
- 360
- 0
i'm trying to swap the 43 and the 435, but instead 435 is printed where 43 should be.
Code:
#include <iostream>
using namespace std;
void print(const int matrix[][2]);
void swap(int matrix[][2]);
int main(){
int matrix[2][2] = {{14, 435}, {43, 65}};
print(matrix);
cout << endl;
swap(matrix);
}
void print(const int matrix[][2]){
for (int i = 0; i < 2; i++){
for (int j = 0; j < 2; j++){
cout << matrix[i][j] << " ";
}
cout << endl;
}
}
void swap(int matrix[][2]){
for (int r = 0; r < 2; r++){
for (int c = 0; c < 2; c++){
int temp = matrix[r][c];
matrix[r][c] = matrix[c][r];
matrix[c][r]= temp;
cout << matrix[c][r] << " ";
}
cout << endl;
}
}