9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit 7d24322031b726cfde107e0ce3e5cdcd19712496
parent f401901fd5c9a51de576710bbba025477bfe4155
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Tue, 30 Mar 2021 00:22:56 -0300

Update: Added ex43.c

Diffstat:
Aguia03/ex43.c | 28++++++++++++++++++++++++++++
1 file changed, 28 insertions(+), 0 deletions(-)
diff --git a/guia03/ex43.c b/guia03/ex43.c
@@ -0,0 +1,28 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#define N 4
+
+int main (void)
+{
+    double matrix[N][N];
+    double trace;
+
+    srand((unsigned int)time(NULL));
+
+    for(size_t i = 0; i < N; i++) {
+        putchar('(');
+        putchar(' ');
+        for(size_t j = 0; j < N; j++) {
+            matrix[i][j] = ((double)rand()/(double)(RAND_MAX)) * 20;
+            printf("%5.2f ", matrix[i][j]);
+        }
+        putchar(')');
+        putchar('\n');
+        trace += matrix[i][i];
+    }
+
+    printf("\nTrace = %2.2f.-\n", trace);
+    return 0;
+}