hey guys am having a problem using if statements in my nested loop....am searching for an element(x) in my 2d array if the element is found a coordinate position (i,j) should be outputted...if element is not found output "-1" but my code outputs "-1" even when the element is there please help am desperate need to get this done so i can finish matrix operations......thanx in advance
The problem is at lines 51-52, you're displaying -1 on the first non-match, then breaking out of both loops.
This really makes more sense written as a function.
1 2 3 4 5 6 7
bool Find (<matrix<int> &arr, int asize)
{ for (int i=0; i<asize; i++)
for (int j=0; j<asize; j++)
if (arr[i][j]==x)
returntrue; // found match
returnfalse; // No match
}