2d array & nested for loops

I have the following array

int myarray[10][20]

I would like to put 5 in the first row and then 10 in the remaining rows.
5 10 10 10 10 10 10 10 10 10

similarly 10 in the first column and then I want my next element to be the twice of the previous element.

10
20
40
80

I can't figure it out. I think I need a nested for loop but I'm not sure how to execute this.



Last edited on
What is your attempt? What exactly is it that you do not understand?
I wanted to populate an array and the array has 10 ROWS and 20 COLUMNS
The requirement states that I need to initialize the array in such a way that the digit 5 is in the first row which would be array[0][0] and then in the remaining rows initialize the digit 10.

oh and btw it is a 2d array

int myarray [10][20]

output should be like this:
5
10
10
10
10
10
10
10
10
10

I don't know how to code it:(
You need two nested loops. See:

http://www.cplusplus.com/doc/tutorial/control/

How [for] loops are coded. The output is the value multiplied with the loop index. Further more you need an if -> index == 1 -> output: 5 * index else output: 10 * index.

For output see:

http://www.cplusplus.com/reference/iostream/cout/?kw=cout
http://www.cplusplus.com/reference/ostream/ostream/operator%3C%3C/
Topic archived. No new replies allowed.