Print boundary elements of the matrix

C program to print boundary elements of the matrix.

Program

#include<stdio.h>
#include<conio.h>
#define MAX 10

void read_matrix(int mat[MAX][MAX], int row, int col)
{
    int i, j;
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            printf("Element [%d][%d]\t:",i,j);
            scanf("%d",&mat[i][j]);
        }
    }
}

void print_matrix(int mat[MAX][MAX], int row, int col)
{
    int i, j;
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            printf("%d\t",mat[i][j]);
        }
        printf("\n");
    }
}

void print_border(int mat[MAX][MAX], int row, int col)
{
    int i, j;

    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            if(i==0 || i == row-1 || j==0 || j==col-1)
            {
                printf("%d\t",mat[i][j]);
            }
            else
            {
                printf(" \t");
            }
        }
        printf("\n");
    }
}

void main()
{
    int mat[MAX][MAX];
    int row, col;

    printf("Enter the number of rows\t:");
    scanf("%d",&row);
    printf("Enter the number of columns\t:");
    scanf("%d",&col);

    printf("Enter the elements of the matrix\n");
    read_matrix(mat, row, col);

    printf("\nMatrix entered is\n");
    print_matrix(mat, row, col);

    printf("\nBoundary elements of the matrix are\n");
    print_border(mat, row, col);

    getch();
}

Output

Enter the number of rows        :5
Enter the number of columns     :5
Enter the elements of the matrix
Element [0][0]  :1
Element [0][1]  :2
Element [0][2]  :3
Element [0][3]  :4
Element [0][4]  :5
Element [1][0]  :6
Element [1][1]  :7
Element [1][2]  :8
Element [1][3]  :9
Element [1][4]  :10
Element [2][0]  :11
Element [2][1]  :12
Element [2][2]  :23
Element [2][3]  :22
Element [2][4]  :34
Element [3][0]  :33
Element [3][1]  :45
Element [3][2]  :44
Element [3][3]  :56
Element [3][4]  :55
Element [4][0]  :67
Element [4][1]  :66
Element [4][2]  :78
Element [4][3]  :77
Element [4][4]  :89

Matrix entered is
1       2       3       4       5
6       7       8       9       10
11      12      23      22      34
33      45      44      56      55
67      66      78      77      89

Boundary elements of the matrix are
1       2       3       4       5
6                               10
11                              34
33                              55
67      66      78      77      89