Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adicionando mais dois tipos de funções
- Loading branch information
1 parent
91a411b
commit 46053a1
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func multiplicacao(a, b int) int { | ||
return a * b | ||
} | ||
|
||
func exec(funcao func(int, int) int, p1, p2 int) int { | ||
return funcao(p1, p2) | ||
} | ||
|
||
func main() { | ||
resultado := exec(multiplicacao, 3, 4) | ||
fmt.Println(resultado) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func media(numeros ...float64) float64 { | ||
total := 0.0 | ||
for _, num := range numeros { | ||
total += num | ||
} | ||
return total / float64(len(numeros)) | ||
} | ||
|
||
func main() { | ||
fmt.Printf("Média: %.2f", media(9.6, 5.9, 8.9, 6.9)) | ||
} |