Can someone please show me how this was solved?

Okay, here is the question, and the answers are below, but I have no idea how the answer was arrived at:

Show the exact output, given

int Numbers [5] [5] =

{30,31,32,33,34,
35,36,37,38,39,
40,41,41,43,44
45,46,47,48,49,
50,51,52,53,54};

int Row;
int Column;

for (Row = 3; Row ,= 4; Row ++)
{

for (Column = 2; Column ,=4; Column ++)

cout << Numbers [Row] [Column]
<< "--";

cout << '\n';

}

The answer is:

47--48--49--
52--53--54--

Thanks in advance!
Joanie
Last edited on
I am not understanding your question. If I clean up the code a little you might see how it was arrived at. It looks like we are doing matrix math of some form from the description.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int Numbers [5] [5] =  { 30,31,32,33,34,
                                      35,36,37,38,39,
                                      40,41,41,43,44,
                                      45,46,47,48,49,
                                      50,51,52,53,54 };

int Row;
int Column;

for (Row = 3; Row <= 4; Row ++)
{

       for (Column = 2; Column <= 4; Column ++)
       {
              cout << Numbers [Row] [Column] << "--";
       }
       
       cout << '\n';

}
First off there appear to be a few extra comma's, I don't know if that's your typo or part of the problem. Just remember that '0' is a number in C\C++ and you should be able to see it. As for how I would arrive at the answer personally I would have written it into an IDE and compiled it.
Topic archived. No new replies allowed.