1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #define N 4 5 6 double getnum(void); 7 8 int main (void) 9 { 10 double matrix[N][N]; 11 double trace; 12 13 for(size_t i = 0; i < N; i++) { 14 putchar('('); 15 putchar(' '); 16 for(size_t j = 0; j < N; j++) { 17 matrix[i][j] = getnum(); 18 printf("%5.2f ", matrix[i][j]); 19 } 20 putchar(')'); 21 putchar('\n'); 22 trace += matrix[i][i]; 23 } 24 25 printf("\nTrace = %2.2f.-\n", trace); 26 return 0; 27 } 28 29 double getnum(void) 30 { 31 char aux, buffer[300]; 32 33 for(size_t i = 0; aux = (getchar() != '\n'); i++) 34 buffer[i] = aux; 35 36 return strtod(buffer, NULL); 37 }