Desafío: Encontrar el Elemento Más Grande en una Cuadrícula
Tarea
- A continuación se muestra un código sin terminar para encontrar el elemento
int
más grande en una matriz o rejilla de 4x4. Lee el código y complétalo sustituyendo los espacios en blanco (___
) por el código apropiado.
index.go
1234567891011121314151617181920212223242526272829303132333435363738package 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) }
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 5. Capítulo 9
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Suggested prompts:
Can you explain how the findMax function works?
What does rand.Intn(100) do in this code?
Can you show how to modify this code for a different matrix size?
Awesome!
Completion rate improved to 1.96
Desafío: Encontrar el Elemento Más Grande en una Cuadrícula
Desliza para mostrar el menú
Tarea
- A continuación se muestra un código sin terminar para encontrar el elemento
int
más grande en una matriz o rejilla de 4x4. Lee el código y complétalo sustituyendo los espacios en blanco (___
) por el código apropiado.
index.go
1234567891011121314151617181920212223242526272829303132333435363738package 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) }
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 5. Capítulo 9