Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Défi : Trouver le Plus Grand Élément dans une Grille | Tableaux et Slices
Introduction à Golang

bookDéfi : Trouver le Plus Grand Élément dans une Grille

Tâche

Vous trouverez ci-dessous un code inachevé permettant de trouver le plus grand élément int dans une matrice ou une grille 4x4. Lisez le code et complétez-le en remplaçant les espaces vides (___) par le code approprié.

index.go

index.go

copy
1234567891011121314151617181920212223242526272829303132333435363738
package main import "fmt" // The `rand` module contains the Intn method which returns a random integer. import "math/rand" func findMax(___) int { var max int = arr[0][0] for i := 0; i < 4; i++ { for j := 0; j < 4; j++ { if arr[i][j] > max { max = ___ } } } return ___ } func getRandomArray() [4][4] int { var arr ___ ___ for i := 0; i < 4; i++ { for j := 0; j < 4; j++ { // Syntax: rand.Intn(max) // 0 <= Returned Value < max // return value may be 0, cannot be `max` arr[i][j] = rand.Intn(100) } } return arr } func main() { var numbers = getRandomArray() var max = findMax(___) fmt.Println(numbers) fmt.Println("Maximum:", max) }

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 5. Chapitre 9

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Suggested prompts:

Can you explain how the findMax function works?

What does rand.Intn(100) do in this code?

Can you show an example output of this program?

Awesome!

Completion rate improved to 1.96

bookDéfi : Trouver le Plus Grand Élément dans une Grille

Glissez pour afficher le menu

Tâche

Vous trouverez ci-dessous un code inachevé permettant de trouver le plus grand élément int dans une matrice ou une grille 4x4. Lisez le code et complétez-le en remplaçant les espaces vides (___) par le code approprié.

index.go

index.go

copy
1234567891011121314151617181920212223242526272829303132333435363738
package main import "fmt" // The `rand` module contains the Intn method which returns a random integer. import "math/rand" func findMax(___) int { var max int = arr[0][0] for i := 0; i < 4; i++ { for j := 0; j < 4; j++ { if arr[i][j] > max { max = ___ } } } return ___ } func getRandomArray() [4][4] int { var arr ___ ___ for i := 0; i < 4; i++ { for j := 0; j < 4; j++ { // Syntax: rand.Intn(max) // 0 <= Returned Value < max // return value may be 0, cannot be `max` arr[i][j] = rand.Intn(100) } } return arr } func main() { var numbers = getRandomArray() var max = findMax(___) fmt.Println(numbers) fmt.Println("Maximum:", max) }

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 5. Chapitre 9
some-alt