문제
The absolute value of a number is its distance from zero. Compute it with an if statement instead of a built-in abs function.
Implement absolute_value(n).
Input
n: Any integer.
Output
Return n if it is zero or positive, otherwise -n.
제약 조건
-1,000,000,000 ≤ n ≤ 1,000,000,000
예시
예시 1
입력:
n = -42
예상 출력:
expected = 42
입력:
long long n = -42;
예상 출력:
long long expected = 42;
입력:
long n = -42;
예상 출력:
long expected = 42;
설명
-42 is negative, so the answer is 42.
예시 2
입력:
n = 15
예상 출력:
expected = 15
입력:
long long n = 15;
예상 출력:
long long expected = 15;
입력:
long n = 15;
예상 출력:
long expected = 15;
설명
15 is already positive, so it stays 15.
참고 자료
이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.