Answer:
The solution code is written in Python
- input_numbers = [5, 7, 1, 12, 9, 34, 22, 97, 112]
-
- evenVec = []
- oddVec = []
-
- for x in input_numbers:
- if x % 2 == 0:
- evenVec.append(x)
- else:
- oddVec.append(x)
-
- num2D = [evenVec, oddVec]
-
- print(num2D)
Explanation:
Let's create a sample input numbers that mixed with odd and even values (Line 1)
Next, create evenVec and oddVec variables to hold the even and odd numbers from the input_numbers (Line 3 - 4).
Create a for-loop to traverse through the input_numbers and check if current number, x, is divisible by 2 using the modulus operator %. If so, x % 2 will be evaluated to 0 and append the current x to evenVec or else append to oddVec (Line 6 - 10).
Next, create a variable num2D to hold the two dimensional arrays with first column is evenVec and second column is oddVec (Line 12).
When printing the num2D (Line 14), we shall get
[[12, 34, 22, 112], [5, 7, 1, 9, 97]]