9511_workbook

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

Update;

Diffstat:
Aguia03/ex44.c | 37+++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+), 0 deletions(-)
diff --git a/guia03/ex44.c b/guia03/ex44.c
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#define N 4
+
+double getnum(void);
+
+int main (void)
+{
+    double matrix[N][N];
+    double trace;
+
+    for(size_t i = 0; i < N; i++) {
+        putchar('(');
+        putchar(' ');
+        for(size_t j = 0; j < N; j++) {
+            matrix[i][j] = getnum();
+            printf("%5.2f ", matrix[i][j]);
+        }
+        putchar(')');
+        putchar('\n');
+        trace += matrix[i][i];
+    }
+
+    printf("\nTrace = %2.2f.-\n", trace);
+    return 0;
+}
+
+double getnum(void)
+{
+    char aux, buffer[300];
+
+    for(size_t i = 0; aux = (getchar() != '\n'); i++)
+        buffer[i] = aux;
+    
+    return strtod(buffer, NULL);
+}