#include<stdio.h>
#include<conio.h>
#define r 3
#define c 3
void main(){
int a[r][c],sum=0,i,j;
clrscr();
printf("Enter Elements of a Matrix.\n");
for(i=0;i<r;i++){
for(j=0;j<c;j++){
printf("Enter A[%d][%d] = ",i,j);
scanf("%d",&a[i][j]);
}
}
for(i=0;i<r;i++){
for(j=0;j<c;j++){
if(i==j)
sum=sum+a[i][j];
}
}
printf("Sum of diagonal elements of given matrix is = ",sum);
getch();
}
No comments:
Post a Comment