Bird
Raised Fist0
Goprogramming~20 mins

Arithmetic operators in Go - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. Which arithmetic operator in Go is used to find the remainder of a division?
easy
A. /
B. +
C. *
D. %

Solution

  1. Step 1: Understand the remainder operation

    The remainder operator returns what is left after division.
  2. Step 2: Identify the correct operator in Go

    In Go, the remainder operator is represented by the percent sign '%'.
  3. Final Answer:

    % -> Option D
  4. Quick Check:

    Remainder = % [OK]
Hint: Remainder uses % like in many languages [OK]
Common Mistakes:
  • Confusing division / with remainder %
  • Using * for remainder
  • Using + for remainder
2. Which of the following is the correct way to write a multiplication operation in Go?
easy
A. a x b
B. a . b
C. a * b
D. a & b

Solution

  1. Step 1: Recall Go's multiplication syntax

    Go uses the asterisk '*' symbol for multiplication.
  2. Step 2: Check each option

    Only 'a * b' uses the correct multiplication operator.
  3. Final Answer:

    a * b -> Option C
  4. Quick Check:

    Multiplication = * [OK]
Hint: Use * for multiplication, not x or & [OK]
Common Mistakes:
  • Using 'x' instead of '*'
  • Using '.' or '&' for multiplication
  • Confusing syntax with other languages
3. What is the output of this Go code?
package main
import "fmt"
func main() {
  a := 7
  b := 3
  fmt.Println(a / b)
}
medium
A. 2.3333333
B. 2
C. 3
D. 0

Solution

  1. Step 1: Identify variable types and operation

    Both a and b are integers, so division is integer division.
  2. Step 2: Calculate integer division result

    7 divided by 3 is 2.333..., but integer division drops decimals, so result is 2.
  3. Final Answer:

    2 -> Option B
  4. Quick Check:

    Integer division 7/3 = 2 [OK]
Hint: Integer division drops decimals, result is int [OK]
Common Mistakes:
  • Expecting float result
  • Confusing integer division with float division
  • Using wrong operator
4. Find the error in this Go code snippet:
package main
import "fmt"
func main() {
  x := 10
  y := 0
  fmt.Println(x / y)
}
medium
A. Division by zero causes runtime panic
B. Syntax error: missing semicolon
C. Variable y is not declared
D. No error, prints 0

Solution

  1. Step 1: Analyze the division operation

    The code divides x by y, where y is zero.
  2. Step 2: Understand Go's behavior on division by zero

    Dividing by zero causes a runtime panic (error) in Go.
  3. Final Answer:

    Division by zero causes runtime panic -> Option A
  4. Quick Check:

    Division by zero = runtime panic [OK]
Hint: Never divide by zero; it crashes the program [OK]
Common Mistakes:
  • Thinking it prints 0
  • Expecting compile-time error
  • Ignoring runtime panic
5. Given the Go code below, what is the output?
package main
import "fmt"
func main() {
  a := 15
  b := 4
  c := a % b
  d := a / b
  fmt.Println(c + d)
}
hard
A. 6
B. 3
C. 19
D. 4

Solution

  1. Step 1: Calculate remainder c = a % b

    15 % 4 equals 3 because 4*3=12 and 15-12=3.
  2. Step 2: Calculate integer division d = a / b

    15 / 4 equals 3 because integer division drops decimals.
  3. Step 3: Add c + d

    3 + 3 equals 6.
  4. Final Answer:

    6 -> Option A
  5. Quick Check:

    15 % 4 = 3, 15 / 4 = 3, 3 + 3 = 6 [OK]
Hint: Add remainder and integer division results carefully [OK]
Common Mistakes:
  • Miscomputing remainder
  • Using float division instead of integer
  • Adding wrong values
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard