i'm trying to swap the 43 and the 435, but instead 435 is printed where 43 should be.(adsbygoogle = window.adsbygoogle || []).push({});

Code (Text):

#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;

}

}

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Homework Help: Swapping numbers in a multidimensional array

**Physics Forums | Science Articles, Homework Help, Discussion**