initial import
[staff/goc4/2018bti7061.git] / c-3-libraries / examples / c-arrays / array3.c
1 #include <stdio.h>
2
3 /* function declaration */
4 double getAverage(int arr[], int size);
5
6 int main ()
7 {
8 /* an int array with 5 elements */
9 int balance[5] = {1000, 2, 3, 17, 50};
10 double avg;
11 /* pass pointer to the array as an argument */
12 avg = getAverage( balance, 5 ) ;
13 /* output the returned value */
14 printf( "Average value is: %f \n", avg );
15 return 0;
16 }
17
18 double getAverage(int arr[], int size){
19 int i;
20 double avg, sum;
21 for (i = 0; i < size; ++i){
22 sum += arr[i];
23 }
24 avg = sum / size;
25 return avg;
26 }