GoogelAddUnit1

Monday, 16 April 2012

WRITE A C-PROGRAM TO FIND THE TRACE OF A MATRIX OF SIZE M*N.

WRITE A C-PROGRAM TO FIND THE TRACE OF A MATRIX OF SIZE M*N.
AIM:A program to find the trace of a matrix of size m*n.
PROGRAM:
#include<stdio.h>
main()
{
int a[10][10],i,j,sum=0;
printf("enter the values of m,n");
scanf("%d%d",&m,&n);
printf("enter the elements of matrix a");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(i==j)
sum=sum+a[i][j];
printf("trace of a matrix=%d",sum);
}

OUTPUT:
enter the value of m,n
2,2
enter the elements of matrix a
1 2 3 4
trace of a matrix is

4 comments: