diff options
Diffstat (limited to 'mean.c')
| -rw-r--r-- | mean.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -0,0 +1,26 @@ +/* File: mean.c + Calculate the mean value for the elements in an array */ + +#include <stdio.h> + +#define N 8 + +int main() +{ + /*Declare array a with initialization */ + double a[N] = {3.0,21.0,0.0,-3.0,34.0,-14.0,45.0,18.0}; + double sum, + meanval; + + int i; + + sum = 0; + + for(i=0;i<N;i++) + { + sum += a[i]; + } + meanval = sum/(double)N; + printf("The mean value of the array is %f\n",meanval); + return 0; +} |
