//C program to interchange  the elements 
//of first and last row in a matrix
//across rows
#include <stdio.h>

#define n 3 

//Function to swap the element 
//of first and last row
void interchangeFirstLast(int m[][n])
{
    int rows=n;
    
    //Swapping the element between first 
    //and last rows
    for(int i=0;i<n;i++)
    {
        int t=m[0][i];
        m[0][i]=m[rows-1][i];
        m[rows-1][i]=t;
    }
}
//Driver code
int main() 
{
    //input matrix
    int m[n][n]
        ={ {6,3,1},
           {4,5,2},
           {2,4,9} };

    //print input matrix
    printf("Input matrix:\n");
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            printf("%d",m[i][j]);
        }
        printf("\n");
    }

    //call interchangeFirstLast(mat) function.
    //This function swap the element of 
    //first and last rows

    interchangeFirstLast(m);

    //print output matrix
    printf("\nOutput matrix:\n");
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            printf("%d",m[i][j]);
        }
        printf("\n");
    }
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: