How to eliminate the border elements in the 2d array using cpp

Process border cells of matrix

this program will consider only the border elements. I need to know how to get the exact opposite.

1 answer

  • answered 2018-04-17 04:48 Abhishek Keshri

    For all the border elements one of these will always apply:

    (i,j) is in the form of (0,*), (*,0), (N-1, *), (*, N-1)
    

    where N is the size of the matrix.

    int main()
    {
        const int N = 5;
        char mat[5][5] = {
            {'a', 'b', 'c', 'd', 'e'},
            {'f', '-', '-', '-', 'g'},
            {'h', '-', '-', '-', 'i'},
            {'j', '-', '-', '-', 'k'},
            {'l', 'm', 'n', 'o', 'p'}
        };
    
        for (size_t i=1;i<N-1;i++)
        {
            for(size_t j=1;j<N-1;j++)
            {
                printf("%c",mat[i][j]);
            }
            printf("\n");
        }
    }