i m making a program which initializes a 2d Dynamic array by first asking for the number of rows and columns,and then filling the array with random characters.
Then i have to check for a three lettered array in the 2D array,(Horizontally,Vertically,Diagonally).
i m having problem with the conditions for checking the elements.
i have made conditions for checking the elements,which are:
for(int q=0;q<r;q++)
{
for(int p=0;p<c;p++)
{
if(a[q][p]==b[0]) //vertical
{
if (a[q+1][p]==b[1])
{
if (a[q+2][p]==b[2])
cout << endl << "Found at ("<< q << "," << p << ") (" << q+1 << "," << p << ") (" << q+2 <<"," << p << ")"<< endl;
}
}
if(a[q][p]==b[0]) //row
{
if (a[q][p+1]==b[1])
{
if (a[q][p+1]==b[2])
cout << endl << "Found at ("<< q << "," << p << ") (" << q << "," << p+1 << ") (" << q <<"," << p+2 << ")"<< endl;
}
}
if(a[q][p]==b[0]) //diagonal
{
if (a[q+1][p+1]==b[1])
{
if (a[q+2][p+2]==b[2])
cout << endl << "Found at ("<< q << "," << p+1 << ") (" << q << "," << p+1 << ") (" << q +2<<"," << p+2 << ")"<< endl;
}
}
}
}
r==number of rows,c==number of cloumns;
b[3] is the array to be compared with the elements of the array.
i cannot think of the logic,when the program checks certain element and when it does not!