I need help with the following C++ code. The part of the code that is black is t
ID: 3865381 • Letter: I
Question
I need help with the following C++ code. The part of the code that is black is the part I need help with. I am trying to swap the values in row two with the values in row three. There are five total rows.
case '3':
cout<<"After swapping the values in row two with the values in row three: ";
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
user_temp[0][j] = array[1][j];
array[0][j] = array[3][j];
array[0][j] = user_temp[0] [j];
cout<<array[i][j]<<" ";
}
cout<<endl;
}
break;
Explanation / Answer
In the given problem only two have to be swapped ie row two and three.
case '3':
// for swapping row 2 and 3
for(j=0;j<5;j++){
temp = array[1][j];
array[1][j] = array[2][j];
array[2][j] = temp;
}
// To display the matrix
cout<<"After swapping the values in row two with the values in row three: ";
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++){
cout<<" "<<array[i][j]);
}
cout<<" ";
}
break;