int D[5][3] ={
{1, 0, 0},
{0, 1, 0},
{0, 0, 1},
{0, 0, 0},
{0, 0, 0},
};
int classnum=0;
int Sy[1][3]={0 ,0 ,1};
for(int i=0 ;i <5 ;i++)
{
for(int j=0 ;j < 3 ;j++)
{
if(Sy[0][j]== D[i][j])
{
classnum = i;
}
}
}
cout<<"\nclassnum = "<<classnum;
it always shows the classnum=4,it should rather be 2.what is the error i am making?
if you could help me with this...?
You could use a bool
variable as a flag. Set it to true
at the start of each pass of the outer loop .
If any element is not equal, set the flag to false
. If it is still set to true after checking all three elements, you have a match.