Inactive Tutor answered 04/12/20
First, get the index of the middle element using the below assignment:
midElementIndex = (length(Array) + 1)/2
then, use this index to output the middle element as follows:
Array[midElementIndex]
Oscar A.
asked 04/12/20Given a sorted list of integers, output the middle integer. Assume the number of integers is always odd.
Ex: If the input is:
(a negative indicates the end), the output is:
The maximum number of inputs for any test case should not exceed 9. If exceeded, output "Too many inputs".
Hint: First read the data into a vector. Then, based on the number of items, find the middle item.
#include <iostream>
#include <vector> // Must include vector library to use vectors
using namespace std;
int main() {
/* Type your code here. */
return 0;
}
Inactive Tutor answered 04/12/20
First, get the index of the middle element using the below assignment:
midElementIndex = (length(Array) + 1)/2
then, use this index to output the middle element as follows:
Array[midElementIndex]
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.