Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercício: Capítulo 13, Exercício 3 (Nível: 6) #43

Open
vkorbes opened this issue Sep 30, 2020 · 7 comments
Open

Exercício: Capítulo 13, Exercício 3 (Nível: 6) #43

vkorbes opened this issue Sep 30, 2020 · 7 comments

Comments

@vkorbes
Copy link
Owner

vkorbes commented Sep 30, 2020

Exercício: Capítulo 13, Exercício 3 (Nível: 6)

Link para o vídeo:

Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!

@dsmello
Copy link

dsmello commented Oct 1, 2020

@diegoparra
Copy link

fui no simples tbm: https://play.golang.org/p/LdHBH5qIZ5J

@an4kein
Copy link

an4kein commented Feb 25, 2021

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.

@alansantosmg
Copy link

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 é: ")

}

@gomesmatheus
Copy link

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

@wfrsilva
Copy link

Cap. 13 – Exercícios: Nível #6 – 3
https://go.dev/play/p/p8XYuOiQeeU

image

@thiagoCalazans-dev
Copy link

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants