This section contains the Golang functions find output programs (set 2) with their output and explanations.
Program 1:
package main
import "fmt"
func AddMult(num1 int, num2 int) (int, int) {
return num1 + num2, num1 * num2
}
func main() {
var sum = 0
var mul = 0
sum, mul = AddMult(10, 20)
fmt.Println("Addition is : ", sum)
fmt.Println("Multiplication is: ", mul)
}
Program 2:
package main
import "fmt"
func VarArgs(args ...int) {
for _, val := range args {
fmt.Println(val)
}
}
func main() {
VarArgs(10, 20, 30, 40, 50)
}
Answer Program 1:
Output:
Explanation:
Here, we created two functions AddMult() and main(). The AddMult() function is used to addition and multiplication two specified number and return the result to the calling function. In the main() function, here we called AddMult() function and calculated the addition and multiplication of numbers, and printed the result.
Answer Program 2:
Output:
Explanation:
In the above program, we created two functions VarArgs () and main(). The VarArgs() function accepts the variable number of arguments and printed them.
In the main() function, we called VarArgs() function and printed the specified numbers on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer