Read the question, write C++ on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read two integers and print the smaller one.
Use the ternary operator condition ? a : b rather than an if statement.
Input. Two integers a and b.
Output. The smaller integer.
Examples
Input
9 4
Output
4
Input
3 3
Output
3
Hint
- std::cout << (a < b ? a : b) << "\n";
Show correct code
Peek only after you have tried. You can still Check your own version.
#include <iostream>
int main() {
int a, b;
std::cin >> a >> b;
std::cout << (a < b ? a : b) << "\n";
return 0;
}
main.cppC++17 · g++ · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.