C Program to interchange the main diagonal elements of the matrix

C Program to interchange the main diagonal elements of the matrix. This Program will accept a matrix of order M x N and store its elements and interchange the main diagonal elements of the matrix with that of the secondary diagonal elements .   Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/
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-efficients of the matrixn");
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 diagonaln");
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
printf (" %d",ma[i][j]);
}
printf ("n");
}
}
else
printf ("The givan order is not square matrixn");

} /* end of main() */
Matrix Programs
Learn C Programming

You can easily select the code by double clicking on the code area above.