Problem using 2D arrays (matrix)

can someone help me? i have problem in using two dimensional arrays.

X =
2 3 4
5 6 7
2 1 2


Y =
12 13 14
15 16 17
12 11 12

Write a program to declare and at the same time use loops to initialize the 2 dimensional arrays x and y to the matrices A and B respectively.
Write a function method to perform Y-X operation.
Last edited on
Do you expect someone to post the answer?
Yes, because I need to use both one dimensional and two dimensional array.
For the 1 dimensional i have implemented the logic and its working fine.
For the two dimensional , i am not getting the idea. :(
Please help me out.
Last edited on
I can only see that the elements in the second row are those in the first added by 3...
what is the problem that you are having with the 2-D case?
I have got it. Thanks guys

#include<iostream>
using namespace std;
void MyArray (int A[][3], int B[][3]);
int main ()
{

int x[][3] = {{2,3,4},
{5,6,7},
{2,1,2}
};
int y [][3]= {{12,13,14},
{15,16,17},
{12,11,12}
};
cout<<endl;

MyArray(x,y);

}
void MyArray (int A[][3], int B[][3])
{
for( int a = 0; a <= 2; a++)
{
for( int b = 0; b <= 2; b++)
{
cout<<B[a][b] - A[a][b]<<"\t";
}
cout<<endl;
}
cout<<endl<<endl;
}

use loops to initialize the 2 dimensional arrays


You just used loops to do Y - X.
Topic archived. No new replies allowed.