Ads Top

Trace of a matrix program using c

Trace of a matrix, program ,using c ,lab,computer,practicals

Trace of a matrix  program

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,n,m,trace=0;
clrscr();
printf("Input rows and columns of matrix A:\n"):
scanf("%d%d",&n,&m);
if(m==n)
{
printf("Enter the matrix :\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)

{
scanf("%d",&a[i][j]);
}
printf("The given Matrix is :\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)

{
printf("%d\t",a[i][j])'
}
printf("\n"):
}
for(i=0;i<m;i++)
{
trace=trace+a[i][j];
}
printf("The  trace of the matrix  is :%d",trace);
}
else
{
printf("The trace cannot be calculated\n");
}
getch();
}
}


Output

Input rows and columns of matrix A: 2   2
Enter matrix A:1  2   3    4
The given matrix  is :
1    2
3    4
The trace of the matrix is::5

No comments:

Touchfeeds. Powered by Blogger.