#include <stdio.h>
void main ()
{
static int ma[10][10];
int i,j,m,n,a;
printf (“Enetr the order of the matix \n”);
scanf (“%d %d”,&m,&n);
if (m ==n )
{
printf (“Enter the co-efficient s of the matrix\n”);
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
scanf (“%dx%d”,&ma[i][j]);
}
}
printf (“The given matrix is \n”);
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
printf (” %d”,ma[i][j]);
}
printf (“\n”);
}
for (i=0;i<m;++i)
{
a = ma[i][i];
ma[i][i] = ma[i][m-i-1];
ma[i][m-i-1] = a;
}
printf (“The matrix after changing the \n”);
printf (“main diagonal & secondary diagonal\n”);
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
printf (” %d”,ma[i][j]);
}
printf (“\n”);
}
}
else
printf (“The given order is not square matrix\n”);
} /* end of main() */
/*—————————————————-
Output
Enetr the order of the matrix
3 3
Enter the co-efficient s of the matrix
1 2 3
4 5 6
7 8 9
The given matrix is
1 2 3
4 5 6
7 8 9
The matrix after changing the
main diagonal & secondary diagonal
3 2 1
4 5 6
9 8 7
———————————————————-*/
Not Satisfied ? Just search & get the result
Related posts:
- C program to accept a matrix of given order and interchange any two rows and columns in the original matrix
- C program to read a matrix A (MxN) and to find the following using functions a) Sum of the elements of each row b) Sum of the elements of each column c) Find the sum of all the elements of the matrix Output the computed results with suitable headings
- C program to read A (MxN), find the transpose of a given matrix and output both the input matrix and the transposed matrix.
- C Program to check if a given matrix is an identity matrix
- C Program to accept N integer number and store them in an array AR. The odd elements in the AR are copied into OAR and other elements are copied into EAR. Display the contents of OAR and EAR
