Read the question, write C on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read three integers and print the median.
Input. Three integers.
Output. The middle value.
Examples
Input
3 1 2
Output
2
Input
9 9 1
Output
9
Hint
- Sort into three temps, or compare pairwise.
Show correct code
Peek only after you have tried. You can still Check your own version.
#include <stdio.h>
int main(void) {
int a, b, c;
if (scanf("%d %d %d", &a, &b, &c) != 3) return 1;
if (a > b) { int t = a; a = b; b = t; }
if (b > c) { int t = b; b = c; c = t; }
if (a > b) { int t = a; a = b; b = t; }
printf("%d\n", b);
return 0;
}
main.cC17 · gcc · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.