137. C Program to print the Diagonals of the given matrix.
How does this program work?
- In this programme you will learn about how to find the diagonals of the given matrix.
- Matrix elements are stored in array variables.
Here is the code
#include <stdio.h>
int main(void)
{
static int array [10][10];
int i, j, m, n, a = 0, sum = 0;
printf("Enetr the order of the matix \n");
scanf("%d %d", &m, &n);
if(m == n )
{
printf("Enter the co-efficients of the matrix\n");
for (i = 0; i < m; ++i)
{
for(j = 0; j < n; ++j)
{
scanf("%d", &array[i][j]);
}
}
printf("The given matrix is \n");
for(i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
printf("%d\t", array[i][j]);
}
printf("\n");
}
printf("Diagonal Elements are:\n");
for(int i=0; i< m; i++)
{
printf("%d\t%d",array[i][i],array[i][n-i-1]);
printf("\n");
}
}
else
printf("The given order is not square matrix\n");
return 0;
}