Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Finding the Largest Element in a Grid | Arrays and Slices
Introduction to GoLang

bookChallenge: Finding the Largest Element in a Grid

Task

Below is an unfinished code for finding the largest int element in a 4x4 matrix or grid. Read the code and complete it by replacing the blanks (___) with appropriate code.

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

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 5. Kapitel 9

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Awesome!

Completion rate improved to 1.96

bookChallenge: Finding the Largest Element in a Grid

Stryg for at vise menuen

Task

Below is an unfinished code for finding the largest int element in a 4x4 matrix or grid. Read the code and complete it by replacing the blanks (___) with appropriate code.

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

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 5. Kapitel 9
some-alt