Suppose we define the median of a sequence as a number, relative to which exactly half of the elements are smaller, and the second is larger. Find the median turned out, but I found another using size (). It is necessary to find the median of the even series, which I did, but I will repeat with the help of size (), which prevents me from using their value. For example: in the even sorted row {3, 6, 7, 10} the median will be {6, 7} therefore 6 + 7/2 (how do I count if I use the row numbers)?
#include <iostream> #include <vector> #include <algorithm> using std::cout; using std::cin; using std::endl; using std::vector; int main() { vector <double> items; double temps(0); double sum(0); double sum_line(0); setlocale(LC_ALL, "RUS"); cout << " Наберите ряд чисел: для получения Медианы." << endl; while (cin >> temps) items.push_back(temps); cout << " Количество элементов в векторе:" << items.size() << endl; sort(items.begin(), items.end()); for (int i = 0; i < items.size(); ++i) { cout << "[V" << i << "] = " << items[i] << endl; } if (items.size() % 2) cout << " Медиана не чётного ряда = " << items[items.size() - 1] / 2 + 1 << endl; else sum += items.size() / 2; sum_line += items.size() / 2 + 1; cout << sum << endl << sum_line << endl << " Среднее значение этих элементов " << (sum + sum_line) / 2 << endl; // тут хотел посчитать // вычислить их среднее // значение. }