Let's consider a solution using brute force, utilizing the conditional operator. The median among , , will be:
, if b ≤ a ≤ c or b ≥ a ≥ c;
, if a ≤ b ≤ c or a ≥ b ≥ c;
, if a ≤ c ≤ b or a ≥ c ≥ b.
Let's consider a solution using minimum and maximum functions. The median among , , will be a + b + c – \text{min}(a, b, c) – \text{max}(a, b, c).
Let's consider a solution using sorting. We read three numbers into an array of length 3 and sort it. The middle element of the array is the median among the three numbers.
We read the input data. Compute the answer using the formula and output it.
scanf("%d %d %d", &a, &b, &c);
if ((b <= a && a <= c) || (b >= a && a >= c)) res = a;
else if ((a <= b && b <= c) || (a >= b && b >= c)) res = b;
else res = c;
printf("%d\n", res);#include <stdio.h>
int a, b, c, res;
int min(int x, int y) {
return (x < y) ? x : y;
}
int max(int x, int y) {
return (x > y) ? x : y;
}
int main(void) {
scanf("%d %d %d", &a, &b, &c);
res = a + b + c - min(a, min(b, c)) - max(a, max(b, c));
printf("%d\n", res);
return 0;
}#include <cstdio>
#include <algorithm>
using namespace std;
int m[3];
int main(void) {
scanf("%d %d %d", &m[0], &m[1], &m[2]);
sort(m, m+3);
printf("%d\n", m[1]);
return 0;
}import java.util.*;
public class Main {
static int min(int x, int y, int z) {
return Math.min(x, Math.min(y, z));
}
static int max(int x, int y, int z) {
return Math.max(x, Math.max(y, z));
}
public static void main(String[] args) {
Scanner con = new Scanner(System.in);
int a = con.nextInt();
int b = con.nextInt();
int c = con.nextInt();
int res = a + b + c - max(a, b, c) - min(a, b, c);
System.out.println(res);
con.close();
}
}a, b, c = map(int, input().split())
res = a + b + c - min(a, b, c) - max(a, b, c)
print(res)