From slice to ellipsis

Report a typo

The code below contains the function Evens(). The function returns true if all the given numbers are even, otherwise it returns false. The parameter of the function is a slice. You need to rewrite the code using a variadic parameter.

func Evens(numbers []int) bool {
    for _, n := range numbers {
        if n%2 != 0 {
            return false
        }
    }

    return true
}

In the input, you get three numbers. You need to output the result that the function returns.

Sample Input 1:

1 2 3

Sample Output 1:

false
Write a program in Go
package main

import "fmt"

func main() {
var num1, num2, num3 int
fmt.Scan(&num1, &num2, &num3)

fmt.Println(Evens(num1, num2, num3))
}

func Evens(numbers ?) bool {
for _, n := range numbers {
if n%2 != 0 {
return false
}
}

return true
}
___

Create a free account to access the full topic