Write a function to obtain the trace of a given square matrix of order m x m
m. (Trace of a matrix is defined as the sum of leading diagonal elements of
the matrix. )
#include
#include
void main()
{
int a[10][10],m,n,i,j,sum=0;
clrscr();
printf("\nEnter number of rows");
scanf("%d",&m);
printf("\nEnter number of columns");
scanf("%d",&n);
if(m==n)
{
printf("Enter values for matrix");
for(i=0;i
for(j=0;j
printf("\na[%d][%d] value",i,j);
scanf("%d",&a[i][j]);
}
}
printf("\nMatrix\n");
for(i=0;i
for(j=0;j
printf("%d\t",a[i][j]);
}
printf("\n");
}
for(i=0;i
sum+=a[i][i];
}
printf("\nSum of diagonal elements %d",sum);
}
else
{
printf("\nSORRY!!!SQUARE MATRIX REQUIRED!!!");
}
getch();
}
/*Output
Enter number of rows3
Enter number of columns3
Enter values for matrix
a[0][0] value1
a[0][1] value2
a[0][2] value3
a[1][0] value4
a[1][1] value5
a[1][2] value6
a[2][0] value7
a[2][1] value8
a[2][2] value9
Matrix
1 2 3
4 5 6
7 8 9
Sum of diagonal elements 15
*/
Shopping In MUMBAI
Are you searching for Discounts, offers, sale in Mumbai ? You are in the right place. MUMBAI, a shopping haven, has no dearth of great discounts and sales. This blog features the best MUMBAI shopping offers, sale, discounts and deals and bargains CURRENTLY GOING on in Mumbai plus a few free things thrown in on top.
Don't wait for it because once they are gone, they are gone. Hurry!..By clicking the "Like" button you will receive a daily update of discounts, sale, offers going on in Mumbai. LIKE IT.... SHARE IT...njoY.
Wednesday, December 31, 2008
C Program to obtain the trace of a given square matrix of order m x m
Posted by ars at 11:15 AM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment