variadic add example 1
This commit is contained in:
parent
61d9fb0587
commit
63febb3fb7
2 changed files with 13 additions and 0 deletions
10
functions/demo3.go
Normal file
10
functions/demo3.go
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package functions
|
||||||
|
|
||||||
|
func AddVariadic(numbers ...int) int{
|
||||||
|
total := 0
|
||||||
|
for i := 0; i < len(numbers); i++ {
|
||||||
|
total = total + numbers[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
return total
|
||||||
|
}
|
3
main.go
3
main.go
|
@ -28,4 +28,7 @@ func main() {
|
||||||
fmt.Println("Subtract :", result2)
|
fmt.Println("Subtract :", result2)
|
||||||
fmt.Println("Multiply : ", result3)
|
fmt.Println("Multiply : ", result3)
|
||||||
fmt.Println("Divide : ", result4)
|
fmt.Println("Divide : ", result4)
|
||||||
|
|
||||||
|
var result = functions.AddVariadic(1,3,4,5,3)
|
||||||
|
fmt.Println(result)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue