2D array initializing in C++

Hello guys!
i am facing a small problem here i want to know how do we initialize 2d arrays as even or odd in C++ for example Declare a two dimensional array of the type int named Matrix of the size 4 x 4, i.e. 4 rows and 4 columns.
Initialize the array such that the first two columns are initialized to the first 8 even numbers, and the last two
columns are initialized to first 8 odd numbers, display the array Matrix as shown in the sample input/output.

Can Anyone tell me how can i initialize rows and columns to odds and even?
should i use a loop or use random

p.s I am a very beginner so we cant use functions.


Last edited on
Why would you want to use random ??
The numbers are fixed. Odd numbers would be 1, 3, 5 ,7 and so on, even numbers are 0, 2, 4,6 and so on

You declare your array like this:
1
2
3
4
const int NUM_ROWS = 4;
const int NUM_COLS = 4;

int Matrix[NUM_ROWS][NUM_COLS]


To initialize them you could loops if you have learned them already or sth. like this (very tedious):
1
2
Matrix[0][0] = 0;
Matrix[2][0] = 1;

How is the output supposed to look like ?
Topic archived. No new replies allowed.