Open vkorbes opened 4 years ago
fui no simples tbm: https://play.golang.org/p/LdHBH5qIZ5J
https://play.golang.org/p/jygLUCmMqd_s
package main
import "fmt"
/* - Utilize a declaração defer de maneira que demonstre que sua execução
só ocorre ao final do contexto ao qual ela pertence.
*/
func malig(x []int) int {
soma := 0
for _, i := range x {
soma += i
}
return soma
}
func main() {
defer fmt.Println("isso vem depois pq eh um defer")
lista := []int{10, 10, 10, 10, 10}
fmt.Println(malig(lista))
}
Output
50
isso vem depois pq eh um defer
Program exited.
my solution:
package main
import "fmt"
func main() {
a := 10
b := 50
x := a + b
defer fmt.Print(x)
fmt.Print("O resultado da soma de A + B é: ")
}
package main
import "fmt"
func main() {
defer fmt.Println("Acabou a contagem, obrigado a todos os envolvidos")
x := 10
fmt.Println("Vamos contar até", x, "!")
for i := 1; i <= 10; i++ {
fmt.Println(i)
}
}
Cap. 13 – Exercícios: Nível #6 – 3 https://go.dev/play/p/p8XYuOiQeeU
package main
import "fmt"
func main() {
slice := []int{2, 3, 5}
defer fmt.Println("vem depois da soma")
fmt.Println(somaDeVariadico(slice...))
}
func somaDeVariadico(variadico ...int) int {
total := 0
for _, v := range variadico {
total += v
}
return total
}
Exercício: Capítulo 13, Exercício 3 (Nível: 6)
Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!