Advertisement
programusy

Untitled

Mar 2nd, 2023
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. // Calculate the median
  2. std::sort(numbers.begin(), numbers.end());
  3. int median;
  4. if (numbers.size() % 2 == 0) {
  5. median = (numbers[numbers.size() / 2 - 1] + numbers[numbers.size() / 2]) / 2;
  6. } else {
  7. median = numbers[numbers.size() / 2];
  8. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement