Displaying slice info

Report a typo

Emma has created a Go program that takes as input a specific length and capacity and then creates an []int slice that is further stored in the numbers variable.

Your task is to help Emma write the additional required code to print the slice information: len(), cap(), and its elements in the following format:

len=x cap=y elements=[...]

Sample Input 1:

5 7

Sample Output 1:

len=5 cap=7 elements=[0 0 0 0 0]
Write a program in Go
package main

import "fmt"

func main() {
// DO NOT delete or modify the code block below:
var length, capacity int
fmt.Scanln(&length, &capacity)
numbers := make([]int, length, capacity)

// Write the code below to print the `numbers` slice len(), cap(), and its elements:
fmt.Printf("len=%d cap=%d elements=%v", ?, ?, ?)
}
___

Create a free account to access the full topic