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 |a − b|.
Input. Two integers.
Output. Non-negative integer.
Examples
Input
10 3
Output
7
Input
3 10
Output
7
Hint
- std::abs from <cmath> or <cstdlib>.
Show correct code
Peek only after you have tried. You can still Check your own version.
#include <iostream>
#include <cstdlib>
int main() {
int a, b; std::cin >> a >> b;
std::cout << std::abs(a - b) << "\n";
return 0;
}
main.cppC++17 · g++ · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.