summaryrefslogtreecommitdiff
path: root/mean.c
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-02-06 11:26:44 -0500
committerAlexander Pickering <alexandermpickering@gmail.com>2017-02-06 11:26:44 -0500
commit97a693d996c79fb2a008b19750d8bb45512e01a2 (patch)
tree6df17bfe7de7c59f7b1083828d71a91e61fae9fa /mean.c
downloadengr0016-master.tar.gz
engr0016-master.tar.bz2
engr0016-master.zip
Inital commitHEADmaster
Diffstat (limited to 'mean.c')
-rw-r--r--mean.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/mean.c b/mean.c
new file mode 100644
index 0000000..34ec21c
--- /dev/null
+++ b/mean.c
@@ -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;
+}