Question
I don’t understand can you help
5. Given the definition and code fragment: (2 points int matrix[2]13]; int k = 0; for(int i =0; i < 2; i++) for (int j=0, j < 3 ) matrix[i]lj]-k++; The value of matrix[1][1] is
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Above program denotes how many matrix elements need to be crossed to get our required adress.

For example to get a[1][1] we need to get 4 matrix elements like a[0][0], a[0][1], a[0][2], a[1][0]

Program in execution:

K=0;

a[0][0]=k++=0 We need to cross 0 matrix elements.

a[0][1]=k++=1 We need to cross 1 matrix elements.

a[0][2]=k++=2 We need to cross 2 matrix elements.

a[1][0]=k++=3 We need to cross 3 matrix elements.

a[1][1]=k++=4 We need to cross 4 matrix elements.

a[1][2]=k++=5 We need to cross 5 matrix elements.

After Execution:

a=[0,1,2

      3,4,5]

********************************************Other way******************************************

It is also used to find address of our element as our array stored in row major orde.

Row major order:

assume matrix a of order m*n where m is number of rows and n is nummber of columns.

If starting indices of a is 0,0: (Assuming that each integer takes one memory location)

       address of a[i][j] = i*n + j

here a is of order 2*3 i.e. 2 rows and 3 columns and starting with indices 0,0.

       address of a[1][1] = 1*3 + 1 = 4

This array would be stored as follows.

Address

Value

0

a[0][0]

1

a[0][1]

2

a[0][2]

3

a[1][0]

4

a[1][1]

5

a[1][2]

Final answer is a[1][1]=4

Add a comment
Know the answer?
Add Answer to:
I don’t understand can you help 5. Given the definition and code fragment: (2 points int...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT