forked from kedarnathpc/golang-practice-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.go
More file actions
32 lines (27 loc) · 684 Bytes
/
functions.go
File metadata and controls
32 lines (27 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main
import (
"fmt"
)
func main() {
dosomething()
fmt.Println("the sum is", add(3, 5))
sum, length := addall(3, 54, 5, 6, 33, 23, 4)
fmt.Println("the of values is", sum, "and the number of values are", length)
}
// no arguments
func dosomething() {
fmt.Println("Doing something !")
}
// with arguments and return values
func add(a, b int) int { //the (a,b int) is same as (a int, b int), no need to declare separatly for same datatype arguments
return a + b
}
// to receive multiple arguments of same type
// and to return multiple values
func addall(values ...int) (int, int) {
total := 0
for _, v := range values {
total += v
}
return total, len(values)
}