I am working on a two dimensional array to represent a matrix.

int matrix[i][j];

I need to swap all the values of matrix[1][1] to matrix[1][2] .

I am not sure how to do the swap, I did try to use for loop and matrix[1][j+1] , but it did not work.
Please help me if you could, your help is always appreciated.

I have a matrix [3][2]={{1,0}{0,0}{1,1}};
My task is to swap the value of matrix[1][2]={1,0} with matrix[2][2]={0,0}and change the value of matrix[3][2]={1,1} to matrix[1][2]={1,0}.

So I need some sort of for loop to go through array read them, save them then swap switch the values. when I use loop,

for (int m=0;m<3; m++){
for(int k=0;k<2;k++)
{
int swap[m][k]=matrix[m][k];
matrix[m][k]=matrix[m+1][k];
matrix[m+1][k]=swap[m][k];
cout<<""<<swap[m][k];
cout<<""<<matrix[m][k];
}

I get error for m++, even if I change the place for m++ I still get errors.
please give me some advice.

In line one swap is declared as an int and is initialized with an int value.

In line two swap is used as a 2 dimensional array. swap can't be both an int and a 2 dimensional array. swap was declared as an int and never as a 2 dimensional array. Therefore the compiler is telling you it can't be both and it can't convert from one to the other.

Even if i remove the cout<<swap[m][k];
i still have the runtime error. i think the [m+1] jumps the loop resriction of <10 , because I say m+1 it goes to 9+1 , but I don't know how to solve this probelm of for loop withh ++

hi, i'm pradeepk
I didn't get ur question correctly, do u want to swap values of one matrix to other or in the same matrix?

I need to swap it inside the same matrix. I am working on an algorithm where I need to swap the values inside the same matrix with each other but I get the the run time error.

and you use index m+1 where m ranges from 0 to less the 3 then you are indeed overwriting the end of the array with m + 1 as an index. To fix it prevent m from ever being the same size as the last valid index for m. So in this case make the outer loop go from 0 to 2. Say something like this:

const int MAXROW = 3;
const int MAXCOL = 2;
int matrix[MAXROW][MAXCOL];
for(in m = 0; m < MAXROW - 1; ++m)
etc;

i got the answer for ur question (swaping matrix elements)
following is the code

int a[10][10];
int t[10];
//take the values into the matrix
for(j=0;j<c;j++)
{
t[j]=a[0][j];
}
for(i=0;i<r-1;i++)
{
for(j=0;j<c;j++)
{
a[j]=a[i+1][j];
}
}
for(j=0;j<c;j++)
{
a[j]=t[j];
}
//then print the matrix

In this code r is the no of rows in the matrix
& c is the no. of columns in the matrix. t[] is the one dimension array for storing elements temporarily.

I have an Epson receipt printer (Model number: TM-T88V), but I cannot use it. I do not have a POS (point of sale) software that will let me do what ...