C program to find the trace of a given square matrix
#include<stdio.h> #include<conio.h> int main() { int a[5][5],r,c,i,j,sum=0; printf("Enter a number of rows and columns:-"); scanf("%d%d",&r,&c); if(r==c) { printf("\nEnter %d*%d elements in matrix:-\n",r,c); for(i=0;i<r;i++) { for(j=0;j<c;j++) scanf("%d",&a[i][j]); } for(i=0;i<r;i++) sum=sum+a[i][i]; printf("\nTrace of the matrix = %d",sum); } else printf("Not a square matrix. It is not possible to find trace."); return 0; }
Related program of Matrix
0 Comments