Q:

Golang Functions | Find Output Programs | Set 2

belongs to collection: Golang Find Output Programs

0

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)
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer Program 1:

Output:

Addition is      :  30
Multiplication is:  200

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:

10
20
30
40
50

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

total answers (1)

Golang Find Output Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Golang Recursion | Find Output Programs | Set 1... >>
<< Golang Functions | Find Output Programs | Set 1...