Guest User

Untitled

a guest
Dec 14th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. int CountAdjacent(int row, int col, int Matrix[rows][columns])
  2. {
  3.     int Row, Column, count = 0;
  4.     for (int c = -1; c <= 1; c++)
  5.         for (int r = -1; r <= 1; r++)
  6.         {
  7.             if (c == r == 0) // skip element itself
  8.                 continue;
  9.             Row = row + r;
  10.             Column = col + c;
  11.             if (Row < 0 || Row > rows - 1 || Column < 0 || Column > columns - 1) // array borders check
  12.                 continue;
  13.             if (Matrix[row][col] == Matrix[Row][Column])
  14.                 count++;
  15.         }
  16.     return count;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment