Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int CountAdjacent(int row, int col, int Matrix[rows][columns])
- {
- int Row, Column, count = 0;
- for (int c = -1; c <= 1; c++)
- for (int r = -1; r <= 1; r++)
- {
- if (c == r == 0) // skip element itself
- continue;
- Row = row + r;
- Column = col + c;
- if (Row < 0 || Row > rows - 1 || Column < 0 || Column > columns - 1) // array borders check
- continue;
- if (Matrix[row][col] == Matrix[Row][Column])
- count++;
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment