aboutsummaryrefslogtreecommitdiff
path: root/CST116F2021-Lab8/13b/13b.cpp
diff options
context:
space:
mode:
authorJacobAKnox <[email protected]>2021-11-13 09:49:09 -0800
committerJacobAKnox <[email protected]>2021-11-13 09:49:09 -0800
commitfcecfe178999fcf25cc7ad088913626f7f18f1fa (patch)
treef0a41368e63f3c0d808ee960a2daa5c71a044f31 /CST116F2021-Lab8/13b/13b.cpp
parentAdd online IDE url (diff)
downloadcst115-lab8-jacobaknox-fcecfe178999fcf25cc7ad088913626f7f18f1fa.tar.xz
cst115-lab8-jacobaknox-fcecfe178999fcf25cc7ad088913626f7f18f1fa.zip
13 completedHEADmaster
Diffstat (limited to 'CST116F2021-Lab8/13b/13b.cpp')
-rw-r--r--CST116F2021-Lab8/13b/13b.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/CST116F2021-Lab8/13b/13b.cpp b/CST116F2021-Lab8/13b/13b.cpp
new file mode 100644
index 0000000..cb7d5a8
--- /dev/null
+++ b/CST116F2021-Lab8/13b/13b.cpp
@@ -0,0 +1,37 @@
+// 13b.cpp : This file contains the 'main' function. Program execution begins and ends there.
+//
+
+#include <iostream>
+#include <math.h>
+#include <algorithm>
+#include "13b.h"
+
+using namespace std;
+
+const int SIZE = 10;
+
+int main()
+{
+ float nums[SIZE] = { 3, 5.3, 7, 3.7, 2, 9, 10};
+ int amt = 7;
+
+ cout << "The median value in the array is: " << FindMedian(nums, amt);
+}
+
+float FindMedian(float nums[], const int amt)
+{
+ float sum;
+
+ sort(nums, nums + amt);
+
+ if (amt % 2 == 0)
+ {
+ sum = nums[amt / 2 - 1] + nums[amt / 2];
+ return sum / 2.0;
+ }
+ else
+ {
+ return nums[(int)ceil(amt / 2.0)];
+ }
+
+} \ No newline at end of file