In: Computer Science
//C program
#include <stdio.h>
int main()
{
//variable initialization
int B[4][4],i,j,m,n;
int row, col, temp;
//enter user input values to matrix B
printf("\nEnter values to the matrix :: \n");
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{
printf("\nEnter a[%d][%d] value :: ",i,j);
scanf("%d", &B[i][j]);
}
}
//for loop show original matrix
printf("\nThe given matrix is :: \n\n");
for (i = 0; i < 4; ++i)
{
for (j = 0; j < 4; ++j)
{
printf("\t%d", B[i][j]);
}
printf("\n\n");
}
//Interchanges diagonal of the matrix
for(row=0; row < 4; row++)
{
col = row;
temp = B[row][col];
B[row][col] = B[row][(4 - col)-1];
B[row][(4 - col)-1] = temp;
}
// Prints the interchanged diagonals matrix
printf("\nMatrix after diagonals interchanged: \n");
for (i = 0; i < 4; ++i)
{
for (j = 0; j < 4; ++j)
{
printf("\t%d", B[i][j]);
}
printf("\n\n");
}
return 0;
}
Output::
Note:: If you have any queries regarding this please comment.