/*trace of a matrix*/
#include<stdio.h>
#include<math.h>
void
main()
{
int
i,j,a[20][20];
float
s=0.0;
printf("enter
the elements of input matrix:");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
scanf("%d",&a[i][j]);
}
printf("the
input matrix is:");
printf("\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
if(i==j)
s=s+a[i][j];
}
}
printf("\n
the trace is=%f\n",s);
}
RESULT:
enter the elements of input matrix:1 2 3 4
the input matrix is:
1 2
3 4
the trace
is=5.000000
Press any key to continue
No comments:
Post a Comment
Thanks for comment.