×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang Functions | Find Output Programs | Set 2

This section contains the Golang functions find output programs (set 2) with their output and explanations.
Submitted by Nidhi, on August 17, 2021

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

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.


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

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.

Golang Find Output Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.