9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit ba8ab464e58e73105795d922784146a8f0abc52a
parent 9593b1ec348d3e9bc19d653f320e511b44f742c4
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Fri,  9 Apr 2021 00:10:38 -0300

Update: Added ex10.c & ex10.h

Diffstat:
Mguia05/Makefile | 11++++++++---
Aguia05/ex10.c | 16++++++++++++++++
Aguia05/ex10.h | 10++++++++++
Mguia05/main.c | 7+++++--
4 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/guia05/Makefile b/guia05/Makefile
@@ -2,13 +2,18 @@ CC = gcc
 FLAGS = -Wall
 
 ex09: ex09.o main.o
-    echo "this executes first"
-    $(CC) ex09.o main.o
+    $(CC) -lm ex09.o main.o
 
 ex09.o: ex09.h
     $(CC) -c ex09.c
 
-main.o: ex09.h
+ex10: ex09.o ex10.o main.o
+    $(CC) -lm ex09.o ex10.o main.o
+
+ex10.o: ex10.h
+    $(CC) -lm -c ex10.c
+
+main.o: 
     $(CC) -c main.c
 
 clean:
diff --git a/guia05/ex10.c b/guia05/ex10.c
@@ -0,0 +1,16 @@
+#include "ex10.h"
+
+#include <stdio.h>
+
+double standard_deviation(double *arr, size_t len)
+{
+    if(arr == NULL) return -1;
+
+    double sum, am;
+    sum = 0;
+    am = arithmetic_mean(arr, len);
+    for(size_t n = 0; n <= len; n++)
+        sum += pow((arr[n] - am), 2);
+
+    return sqrt(sum / (len + 1));
+}
diff --git a/guia05/ex10.h b/guia05/ex10.h
@@ -0,0 +1,10 @@
+#ifndef _EX10_H_
+#define _EX10_H_
+
+#include <math.h>
+
+#include "ex09.h"
+
+double standard_deviation(double *, size_t len);
+
+#endif
diff --git a/guia05/main.c b/guia05/main.c
@@ -1,14 +1,17 @@
 #include <stdio.h>
 
 #include "ex09.h"
+#include "ex10.h"
 
 int main (void)
 {
     double a[] = {9, 1.50, 3, 8.75};
 
-    double am;
+    double am, sd;
     am = arithmetic_mean(a, 3);
+    sd = standard_deviation(a, 3);
 
-    printf("%f\n", am);
+
+    printf("%f\n%f\n", am, sd);
     return 0;
 }