+ 1

Test

Median number Three different numbers a, b, c are given. Print the median number. Input Integers a, b, c that do not exceed 1000 by absolute value. Output Print the median among three numbers. Input example #1 11 3 7 Output example #1 7 who can do it (c++)

13th Nov 2017, 5:13 PM
Chapay Gahramanov
Chapay Gahramanov - avatar
1 Antwort
+ 1
Here you go. Just note, due to restrictions/limitations of SoloLearn compiler, the loop is going to grab the next pre-entered input instead of prompting you. However, under normal circumstances/compilers, this should accomplish your task. https://code.sololearn.com/cp9R2gGwvwQD/#cpp #include <iostream> #include <cmath> using namespace std; #define MEDIAN(a,b,c) ( (a > b) ? max(b, min(a,c)) : min(b, max(a,c)) ) int getInput(){ int x = 0; while(true){ cout << "Please enter number (<|1000|): " << endl; cin >> x; if(abs(x) > 1000){ cout << "Number out of range! Try again." << endl; continue; } else { break; } } return x; } int main() { int a = 0; int b = 0; int c = 0; a = getInput(); b = getInput(); c = getInput(); cout << "Median: " << MEDIAN(a,b,c); return 0; }
13th Nov 2017, 6:13 PM
AgentSmith