0
0
Goprogramming~20 mins

Arithmetic operators in Go - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Arithmetic Operator Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2: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)
}
A
3
-2
B
3.4
2
C
3
0
D
3
2
Attempts:
2 left
๐Ÿ’ก Hint
Remember that integer division in Go truncates the decimal part.
โ“ Predict Output
intermediate
2: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))
}
A3
B3.5
C3.75
DCompilation error
Attempts:
2 left
๐Ÿ’ก Hint
You need to convert the integer to float64 before division.
โ“ Predict Output
advanced
2: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)
}
A-1
B1
C4
D7
Attempts:
2 left
๐Ÿ’ก Hint
Remember operator precedence: multiplication and division before subtraction and addition.
โ“ Predict Output
advanced
2: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)
}
A
-3
-1
B
-3
-3
C
-3
1
D
-4
1
Attempts:
2 left
๐Ÿ’ก Hint
In Go, integer division truncates toward zero and modulo has the same sign as the dividend.
โ“ Predict Output
expert
2: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)
}
A12.5
B10
CCompilation error
D7
Attempts:
2 left
๐Ÿ’ก Hint
You must convert float64 to int before multiplication with int constant.