[Solved] Check each column and row for duplicate


You may want to pass a single dimension array:

bool latin(int const * const arr, unsigned int capacity)
{
  int counter = 0;
  int s; // Please initialize this.
  for (int row = 0; row < MAXIMUM_ROWS; ++row)
  {
    for (int column = 0; column < MAXIMUM_COLUMNS; ++column)
    {
       const int value = *(arr + row * MAXIMUM_COLUMNS + column);
       if (value == s) // Remember s is not initialized.
       {
         ++counter;
       }
    }
  }
  return counter == 1;
}

In the above code, the slot in the array is accessed by the formula:

value = *(arr + row * MAXIMUM_COLUMNS + column);

The compiler will generate the similar code for accessing a 2 dimensional array, provided that you specify the number of columns, such as (int arr[][MAXIMUM_COLUMNS], int capacity). Because a 2 dimensional array is allocated as a large one dimensional array in memory.

solved Check each column and row for duplicate