PROBLEM 36
Easy

Larger Absolute Value

Programming Basics · C++

</>
STATUS Not solved

TASK

Problem

#36

Given two integers `a` and `b`, print the one with the larger absolute value. If the absolute values are equal, print `a`.

EXAMPLE

Example

Input
3 7
Output
7

LIMITS

Constraints

All integer magnitudes are at most 10^9; divisors are non-zero where used.
📖
LEARN Theory for this problem
+

`if`, comparison operators, and logical operators let a program choose output according to a condition.

Connection to “Larger Absolute Value”: here, intermediate values are best kept in named variables so the formula stays readable and data types remain clear.

💡
NEED HELP? Hints
+

['Write the condition directly and print exactly the required value.', 'After solving “Larger Absolute Value”, verify the algorithm on your own small example and on an allowed boundary case. Print only the required result with no extra text.']

ANSWER Solution
+
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main() {
    long long a, b;
    cin >> a >> b;
    cout << (llabs(a) >= llabs(b) ? a : b) << '\n';
    return 0;
}