9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit 493116077c77d7ce4a3085e8968df1f248cd9e44
parent 82f61a5ffbdbe01c44f23c7d1f5d8e534cb4db0e
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Thu,  1 Apr 2021 18:00:19 -0300

Update: ex46.c now allows user to input custom matrix value besides having a function to initialize them randomly;

Diffstat:
Mguia03/ex46.c | 15++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/guia03/ex46.c b/guia03/ex46.c
@@ -5,6 +5,7 @@
 #define N 3
 #define M 4
 
+void m_load(size_t r, size_t c, double matrix[r][c]);
 void m_initrand(size_t r, size_t c, double matrix[r][c]);
 void m_print(size_t r, size_t c, double matrix[r][c]);
 void m_transpose(size_t r, size_t c, double matrix[r][c], double matrix_t[c][r]);
@@ -14,7 +15,8 @@ int main (void)
     double matrix[N][M];
     double matrix_transpose[M][N];
 
-    m_initrand(N, M, matrix);
+//    m_initrand(N, M, matrix);
+    m_load(N, M, matrix);
     m_print(N, M, matrix);
     putchar('\n');
     
@@ -25,6 +27,17 @@ int main (void)
     return 0;
 }
 
+void m_load(size_t r, size_t c, double matrix[r][c])
+{
+    char buf[20];
+    for(size_t i = 0; i < r; i++) {
+        for(size_t j = 0; j < c; j++) {
+            fgets(buf, 20, stdin);
+            matrix[i][j] = strtod(buf, NULL);    /*    value from stdin    */ 
+        }
+    }
+}
+
 void m_initrand(size_t r, size_t c, double matrix[r][c])
 {
     srand((unsigned int)time(NULL));