9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit 9593b1ec348d3e9bc19d653f320e511b44f742c4
parent 3f5378d5fd418d22128c8f270925d62398373b32
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Thu,  8 Apr 2021 18:46:27 -0300

Update;

Diffstat:
AMakefile | 2++
Dclean.sh | 25-------------------------
Aguia05/Makefile | 15+++++++++++++++
Aguia05/ex09.c | 12++++++++++++
Aguia05/ex09.h | 8++++++++
Aguia05/main.c | 14++++++++++++++
6 files changed, 51 insertions(+), 25 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,2 @@
+clean:
+    rm ./**/*.o
diff --git a/clean.sh b/clean.sh
@@ -1,25 +0,0 @@
-#!/bin/bash
-
-# Removes every a.out from every subfolder where the 
-# script is executed;
-
-# Set the filename;
-file='a.out'
-
-# The path where 'file' is gonna be looked for;
-subfolders=./**/$file
-currentdir=./$file
-
-# First checks  if the file exist in the current directory
-# or in any sub-folder, if exist removes it from everywhere;
-if [ -e $currentdir ] || [ -e $subfolders ];
-then
-        rm -v -f ./**/"$file" 
-        rm -v -f "$file"
-        echo "everithing cleaned succesfully"
-
-# if doesn't exist then does nothing;
-else
-        echo "everything seems clean"
-        echo "there is nothing to do"
-fi
diff --git a/guia05/Makefile b/guia05/Makefile
@@ -0,0 +1,15 @@
+CC = gcc
+FLAGS = -Wall
+
+ex09: ex09.o main.o
+    echo "this executes first"
+    $(CC) ex09.o main.o
+
+ex09.o: ex09.h
+    $(CC) -c ex09.c
+
+main.o: ex09.h
+    $(CC) -c main.c
+
+clean:
+    rm -f *.o *.out
diff --git a/guia05/ex09.c b/guia05/ex09.c
@@ -0,0 +1,12 @@
+#include "ex09.h"
+
+double arithmetic_mean(double *arr, size_t len)
+{
+    if(arr == NULL) return -1;
+
+    double sum = 0;
+    for(size_t i = 0; i <= len; i++)
+        sum += arr[i];
+    
+    return (sum / (len + 1));
+}
diff --git a/guia05/ex09.h b/guia05/ex09.h
@@ -0,0 +1,8 @@
+#ifndef _EX09_H_
+#define _EX09_h_
+
+#include <stddef.h>
+
+double arithmetic_mean(double *, size_t len);
+
+#endif
diff --git a/guia05/main.c b/guia05/main.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+#include "ex09.h"
+
+int main (void)
+{
+    double a[] = {9, 1.50, 3, 8.75};
+
+    double am;
+    am = arithmetic_mean(a, 3);
+
+    printf("%f\n", am);
+    return 0;
+}