Consider a square matrix A of size Nx N and an integer X which is an element of A. Find the row number R and column number C of X in A, and calculate the sum of
#define N 4
int main()
{
int r,c,X;
int Matrix[N][N]= {
{2, 0, 3, 4},
{1, 3, 15, 6},
{2, 0, 9, 8},
{3, 4, 5, 6}
};
X = 15;
for(r=0;r<N;r++)
{
for(c=0;c<N;c++)
{
if(X == Matrix[r][c]) printf("\n\tX = %d belongs to Row = %d, Col = %d",X,r,c);
}
}
}
Comments
Leave a comment