# Thread: Finding All Adjecent Elements in a 2D array in C Language..

1. ## Finding All Adjecent Elements in a 2D array in C Language..

Hi All. I am working on a project where at one point i am stucked. my Question is for example i have the following 2D array containg 3 different integers..

2 2 2 2 1
1 2 2 2 1
3 3 2 3 2
3 1 3 3 1
1 1 2 3 1
1 3 1 3 3
what i want is to find the longest adjacent elements chain of array of any number containing in the array. like in the above array the longest chain is of digit 2.

2 2 2 2
2 2 2
2
Can anyone just Guide me what i have to do for Achieving this Goal. Thanks.

2. You could have two loops, the outer one to hold the value of the current element value then the inner one steps through the entire array and counts the adjacent occurences of the current element,

The below definitely will not work and do the whole thing for you and there are gaps in the logic and things you need to figure out in order to complete the task, and the idea shown definitely depends on your data only being a simple data set say, 0 - 20, otherwise i would do things a bit differently. I am not about to do homework, but it should give you some ideas on one approach to start you off

Code:
```for(i = 0; i < maxVal; i++)
{
currentVal = array[i];
temp = array[i];

for j = 0; j < maxVal; j++)
{

if(array[j] == array[i])
{