Skip to content

Commit

Permalink
Create average.c
Browse files Browse the repository at this point in the history
adding an average function with a test case
  • Loading branch information
lukasb1b authored Aug 30, 2023
1 parent 1302bf4 commit 2d7b364
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions math/average.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <stdio.h>
#include <assert.h>

//average of an array

double average(int avg[]) {
double result = 0;
int size=0;

while(avg[size+1]!='\0'){
size++;
}

for (int i = 0; i < size; i++) {
result += avg[i];
}

return result / size;
}

int main() {
int test[] = {1,2,3,4,5};
assert(average(test)==3);
return 0;
}

0 comments on commit 2d7b364

Please sign in to comment.