write a c programs to find the trace of a given matrix.

1 answer

for an integer matrix,

int trace(int *a,int n) {
int t=0,i;
for (i=0;i<n;i++) {t += *(a[i*n+i])}
return t;
}