Golang as u can see in this code(.go) am trying to input 2d arrays and storing even integers in even array and for odd in odd array. But we can see in its output as i mentioned below after code in comments it skips indexes during input? and even array can't get the even values. What am doing wrong?
package main
import (
"fmt"
)
func main() {
numbers := [4][4]int{}
even := [4]int{}
odd := [4]int{}
row := 4
col := 4
fmt.Println("Enter data in your 2-D Array")
for row = 0; row < 4; row++ {
for col = 0; col < 4; col++ {
fmt.Scanf("%d", &numbers[row][col])
if numbers[row][col]%2 == 0 {
even[row] = numbers[row][col]
} else {
odd[row] = numbers[row][col]
}
}
}
fmt.Println("Printing 2D Arrays", numbers)
fmt.Println("Print Even Array", even)
fmt.Println("Print Odd Array", odd)
}
//My output is as follow
//Printing 2D Arrays [[1 0 2 0] [3 0 4 0] [5 0 6 0] [7 0 8 0]]
//Print Even Array [0 0 0 0]
//Print Odd Array [1 3 5 7]
numbershas 16 elements andevenandoddhave 4 elements for each. so you need 2D array to matcheventandoddelements?