0

hello,
i have this assignment but i got stuck on number 2.
Question 1: Create a 3x3 array, each filled with a digit 1-9 so that the array resembles a num pad. Use for loops and construct 3 different, correct ways to print the elements of this array.

Question 2: Calculate and then print the product of the elements of the first 2 rows of this array.
It has 3 more parts and I know how to do others but don't know how to do number 2.
thank you

3
Contributors
2
Replies
31
Views
1 Year
Discussion Span
Last Post by ryantroop
1

To put it in other words, I believe what you are being asked is to take all the values from the first two rows and multiply them.

If you think of your 3x3 array as an array of arrays:

//demonstrative
int A[3][3] == [ [a,b,c], [d,e,f], [h,i,j] ];

You know the size of your arrays, so you can loop through them A[0][0] through A[0][2] and A[1][0] through A[1][2].

You can do this using two for loops (one for each dimension, that iterates through the sizeof each row), or using a single for loop for each dimension (since you know you only want row 0 and 1.

Alternatively, you can access them by pointer (since that's basically what they are under the hood any how).

Lots of ways to skin the cat..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.