1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 5 #define N 4 6 7 int main (void) 8 { 9 double matrix[N][N]; 10 double trace; 11 12 srand((unsigned int)time(NULL)); 13 14 for(size_t i = 0; i < N; i++) { 15 putchar('('); 16 putchar(' '); 17 for(size_t j = 0; j < N; j++) { 18 matrix[i][j] = ((double)rand()/(double)(RAND_MAX)) * 20; 19 printf("%5.2f ", matrix[i][j]); 20 } 21 putchar(')'); 22 putchar('\n'); 23 trace += matrix[i][i]; 24 } 25 26 printf("\nTrace = %2.2f.-\n", trace); 27 return 0; 28 }