Budget — Inside Interval [-8, 8]
Go Programming Basics · Go
TASK
Problem
An integer `n` is entered. Print `YES` if `n >= -8 && n <= 8` is true; otherwise print `NO`.
EXAMPLE
Example
11
NO
LIMITS
Constraints
- Unless the statement says otherwise, integer inputs have absolute value at most 1,000,000. - Every divisor used in the task is non-zero. - Floating-point test values are chosen so the required arithmetic fits `float64`.
LEARN
Theory for this problem
+
`if` selects a branch from a boolean condition. Combine predicates with `&&`, `||`, and `!` only when their precedence matches the intended logic.
`fmt.Scan`/`fmt.Fscan` parses whitespace-separated input into typed variables. The variable type controls how later arithmetic and comparisons behave.
Apply these rules directly to the task requirement: an integer `n` is entered. Print `YES` if `n >= -8 && n <= 8` is true; otherwise print `NO`.
NEED HELP?
Hints
+
['Write the boolean condition directly, then verify boundary values just below, at, and just above each threshold.', 'Read values in exactly the order stated by the condition.', 'Use the sample input `11` to verify parsing and confirm that the program prints exactly `NO` with no extra text.']
ANSWER
Solution
+
package main
import (
"fmt"
)
func main() {
var n int
fmt.Scan(&n)
if n >= -8 && n <= 8 {
fmt.Println("YES")
} else {
fmt.Println("NO")
}
}