|
|
@@ -0,0 +1,74 @@ |
|
|
|
package main |
|
|
|
|
|
|
|
import "fmt" |
|
|
|
|
|
|
|
func init() { |
|
|
|
fmt.Println("Salut depuis main 1") |
|
|
|
} |
|
|
|
|
|
|
|
func init() { |
|
|
|
fmt.Println("Salut depuis main 2") |
|
|
|
} |
|
|
|
|
|
|
|
func init() { |
|
|
|
fmt.Println("Salut depuis main 3") |
|
|
|
} |
|
|
|
|
|
|
|
func main() { |
|
|
|
fmt.Println("Salut tout le Monde") |
|
|
|
q, r := NamedDivide(15, 6) |
|
|
|
fmt.Printf("Division 15 / 6, Quotient: %d Reste: %d\n", q, r) |
|
|
|
fmt.Printf("Facture: %.2f\n", Facture(8.75, 10.2, 3.7)) |
|
|
|
Bonjour() |
|
|
|
|
|
|
|
Bonjour := func() string { |
|
|
|
return "On cache la fonction externe Bonjour" |
|
|
|
} |
|
|
|
|
|
|
|
TakeFunc(GiveFunc()) |
|
|
|
TakeFunc(Bonjour) |
|
|
|
} |
|
|
|
|
|
|
|
func Bonjour() { |
|
|
|
fmt.Println("Bonjour") |
|
|
|
} |
|
|
|
|
|
|
|
// ceci provoque une erreur de redefinition |
|
|
|
// func Bonjour(m string) { |
|
|
|
// fmt.Println(m) |
|
|
|
// } |
|
|
|
|
|
|
|
func Add(a, b int) int { |
|
|
|
return a + b |
|
|
|
} |
|
|
|
|
|
|
|
func Divide(a, b int) (int, int) { |
|
|
|
return a / b, a % b |
|
|
|
} |
|
|
|
|
|
|
|
func NamedDivide(a, b int) (quotient int, remainder int) { |
|
|
|
quotient, remainder = a/b, a%b |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func TakeFunc(take func() string) { |
|
|
|
data := take() |
|
|
|
fmt.Println(data) |
|
|
|
} |
|
|
|
|
|
|
|
func GiveFunc() func() string { |
|
|
|
f := func() string { |
|
|
|
return "Fonction retour" |
|
|
|
} |
|
|
|
return f |
|
|
|
} |
|
|
|
|
|
|
|
func Facture(mht float64, items ...float64) (total float64) { |
|
|
|
for _, item := range items { |
|
|
|
total += item |
|
|
|
} |
|
|
|
|
|
|
|
total *= (1 + mht*.01) |
|
|
|
return |
|
|
|
} |
|
|
|
|