149k views
5 votes
Write a program that takes in three integers and outputs the median value (not the largest or smallest value). End the output with a newline. Ex: If the input is: 7 1 4 the output is: 4

in C++ please

2 Answers

5 votes

Final answer:

To find the median value from three integers in C++, you can use a sorting algorithm and output the middle value.

Step-by-step explanation:

To find the median value from three integers, you can use a sorting algorithm. Here's one way to do it:

  1. Take three integer inputs.
  2. Sort the three integers in ascending order.
  3. The median will be the middle value.
  4. Output the median value.

Here's an example program in C++:

#include <iostream>
#include <algorithm>

int main() {
int num1, num2, num3;
std::cin >> num1 >> num2 >> num3;

int median;

// Sort the numbers
int numbers[] = {num1, num2, num3};
std::sort(numbers, numbers + 3);

// Find the median
median = numbers[1];

// Output the median
std::cout << median << std::endl;

return 0;
}
User Israel Morales
by
4.6k points
3 votes
Hope this helps bro
Write a program that takes in three integers and outputs the median value (not the-example-1
User Srujan Maddula
by
5.1k points