076. Write a program to accept a M x N matrix and print addition of diagonal elements of that matrix in C language

 
#include<stdio.h>
#include<conio.h>
main()
{
	int i,j,m,a[5][5],sum=0;
	clrscr();
	printf("Enter order of matrix :\n");
	scanf("%d",&m);
	printf("Enter matrix elements.....\n");
	for(i=0;i<m;i++)
		for(j=0;j<m;j++)
			scanf("%d",&a[i][j]);
 
	for(i=0;i<m;i++)
		for(j=0;j<m;j++)
			if(i==j)
				sum=sum+a[i][j];
 
	printf("\nSum of diagonal elements.....%d",sum);
	getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *