Numbers sequence

Report a typo

You need to output a sequence of cubes of numbers from 1 to 5:

1
8
27
64
125

Which of the code examples below is guaranteed to produce it in this order?

a)

func main() {
    for i := 1; i <= 5; i++ {
        println(i * i * i)
    }
}

b)

func cube(i int) {
    println(i * i * i)
}

func main() {
    for i := 1; i <= 5; i++ {
        go cube(i)
    }
}

c)

func cube(i int) {
    println(i * i * i)
}

func main() {
    for i := 1; i <= 5; i++ {
        cube(i)
    }
}

d)

func cube(i int) {
    println(i * i * i)
}

func main() {
    for i := 1; i <= 5; i++ {
        go cube(i)
        time.Sleep(time.Microsecond)
    }
}

e)

func cube(i int) {
    println(i * i * i)
}

func main() {
    for i := 1; i <= 5; i++ {
        go cube(i)
    }
    time.Sleep(time.Second)
}
Select one or more options from the list
___

Create a free account to access the full topic