Challenge - 5 Problems
Arithmetic Operator Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of integer division and modulo
What is the output of this Go program?
Go
package main import "fmt" func main() { a := 17 b := 5 fmt.Println(a / b) fmt.Println(a % b) }
Attempts:
2 left
๐ก Hint
Remember that integer division in Go truncates the decimal part.
โ Incorrect
In Go, dividing two integers results in integer division, so 17 / 5 equals 3. The modulo operator % gives the remainder, so 17 % 5 equals 2.
โ Predict Output
intermediate2:00remaining
Output of mixed float and integer arithmetic
What is the output of this Go program?
Go
package main import "fmt" func main() { var x float64 = 7.5 var y int = 2 fmt.Println(x / float64(y)) }
Attempts:
2 left
๐ก Hint
You need to convert the integer to float64 before division.
โ Incorrect
Go does not allow direct arithmetic between different types. Converting y to float64 allows floating-point division, so 7.5 / 2.0 equals 3.75.
โ Predict Output
advanced2:00remaining
Output of complex arithmetic expression
What is the output of this Go program?
Go
package main import "fmt" func main() { a := 10 b := 3 c := 4 result := a - b*c + b/b fmt.Println(result) }
Attempts:
2 left
๐ก Hint
Remember operator precedence: multiplication and division before subtraction and addition.
โ Incorrect
Operator precedence: * and / first (left-to-right). b*c = 3*4 = 12, b/b = 3/3 = 1. Then - and + left-to-right: 10 - 12 + 1 = -1.
โ Predict Output
advanced2:00remaining
Output of arithmetic with negative numbers
What is the output of this Go program?
Go
package main import "fmt" func main() { x := -15 y := 4 fmt.Println(x / y) fmt.Println(x % y) }
Attempts:
2 left
๐ก Hint
In Go, integer division truncates toward zero and modulo has the same sign as the dividend.
โ Incorrect
Integer division truncates toward zero: -15 / 4 = -3. Modulo sign matches dividend: -15 % 4 = -15 - (-3)*4 = -15 + 12 = -3.
โ Predict Output
expert2:00remaining
Output of arithmetic with mixed types and constants
What is the output of this Go program?
Go
package main import "fmt" func main() { const a = 5 var b float64 = 2.5 c := a * int(b) fmt.Println(c) }
Attempts:
2 left
๐ก Hint
You must convert float64 to int before multiplication with int constant.
โ Incorrect
The constant a is int 5, b is float64 2.5. Converting b to int truncates to 2, so c = 5 * 2 = 10.