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 largest.
std::max({a, b, c}) needs the initializer-list form (with braces) to take three arguments.
Input. Three integers separated by space or newline.
Output. One integer: the largest.
Examples
Input
3 9 4
Output
9
Input
5 5 2
Output
5
Hint
- #include <algorithm> for std::max.
- std::max({a, b, c}) compares all three.
Show correct code
Peek only after you have tried. You can still Check your own version.
#include <iostream>
#include <algorithm>
int main() {
int a, b, c;
std::cin >> a >> b >> c;
std::cout << std::max({a, b, c}) << "\n";
return 0;
}
main.cppC++17 · g++ · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.