Home   Easy-Code    Forum  Updater 
Twitter Facebook



Program to print the diagonal elements of a matrix using c

Critics Rating:

Users Rating:



       /* PROGRAM TO PRINT THE DIAGONAL ELEMENTS OF A MATRIX */



#include <stdio.h>

main()

{

int a[5][5],i,j,m,n;

clrscr();

printf("ENTER THE ORDER OF ANY SQUARE MATRIX\n");

scanf("%d%d",&m,&n);

printf("ENTER %d NUMBERS\n",m*n);

for (i=0;i
   for (j=0;j
    scanf("%d",&a[i][j]);

clrscr();

printf("THE GIVEN MATRIX IS\n\n");

for (i=0;i
{

   for (j=0;j
    printf("%3d",a[i][j]);

   printf("\n\n");

}

printf("\nTHE DIAGONAL ELEMENTS ARE\n\n");

for (i=0;i
{

    for (j=0;j
    {

    if (i==j || i+j==m-1)

       printf("%3d",a[i][j]);

    else

       printf(" ");

    }

    printf("\n");

}

getch();

}

Courtesy, Source, References & Regards: Kishore AVGK

While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright@2009-2011 by KuGuNi.com. All Rights Reserved.