#include<stdio.h>
#include<conio.h>
void main()
{
int a[2][2],i,j,sum=0;
printf("enter the matrix:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&a[i][j]);
printf("\t");
}
printf("\n");
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
if(i==j)
{
sum+=a[i][j];
}
}
}
printf("the sum of diagonal element of matrix is %d",sum);
}
#include<conio.h>
void main()
{
int a[2][2],i,j,sum=0;
printf("enter the matrix:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&a[i][j]);
printf("\t");
}
printf("\n");
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
if(i==j)
{
sum+=a[i][j];
}
}
}
printf("the sum of diagonal element of matrix is %d",sum);
}
No comments:
Post a Comment