Skip to content

Commit

Permalink
14.2 funcoes variaticas
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruteski committed Mar 27, 2024
1 parent 42c433d commit a278c07
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 14-funcoes_avacadas/14.2-funcoes_variaticas/funcoes_variaticas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import "fmt"

// nao precisa especificar a quantidade de parametros que a func vai receber

func soma(numeros ...int) int {
total := 0

for _, numero := range numeros {
total += numero
}

return total
}

func escrever(texto string, numeros ...int) {
for _, numero := range numeros {
fmt.Println(texto, numero)
}
}

func main() {
total := soma(1, 2, 3, 4, 5, 6, 7, 8, 9)
fmt.Println(total)

escrever("numero:", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
}

0 comments on commit a278c07

Please sign in to comment.