+2 votes
183 views
a[-25.....+25, -25......+25], Base address=0 and size of element = 100 bytes

Find the location of a[20][22] ?

Also Matrix is upper triangular matrix with row major order
asked | 183 views
number of elements we shud cross before accessing a[20][22] is 1307. 1308th element is a[20][22]
51+50+49+48....7 these are the elements till 19th row. now in 20th row we will have to cross 2 elements.
so total elements to cross= 51+50...+7+2 =1307. index of a[20][22] = 1307.
0th element address--->0
1st element address--->100
2nd--->200
>
>
100th element address= 10000
>
1307th element address= 130700
by a[x][y] we mean there are 'x' 1D arrays of size 'y' isnt it? why is it a[50][50]
I applied same method @Anusha. So I think 130700 is correct
Array stores 51 elements. So, it should be a[51][51], index varies from 0 to 50
not abel to get 1307!!!!!
summation of 51 to 33 ie 19th term of the sequence is 798. kindly help in calculating
not able to get the calculation of the elements of first 19 rows

## 1 Answer

+8 votes
Best answer

$130700$ is correct !

• $ub_1$ = upper bound index on rows
• $ub_2$ = upper bound index on columns

\begin{align*} &\Rightarrow \text{LOC}\left ( a[X][Y] \right ) = \text{BA} + \left ( \frac{\text{n}\_\text{row}(\text{n}\_\text{row}+1)}{2} - \frac{(\text{ub}_1 - X +1)(\text{ub}_1 - X +2)}{2} + Y-X \right )*E \\ & \Rightarrow \text{LOC}\left ( a[X][Y] \right ) = 0 + \left ( \frac{51*52}{2} - \frac{6*7}{2} + 2 \right )*100 \\ & \Rightarrow \text{LOC}\left ( a[X][Y] \right ) = 130700 \\ \end{align*}

answered by Veteran (47k points)
edited
Nice explanation :)
@Debashish, We can use this as a formula, right ?

Otherwise, i always calculated it manually.
yes this is valid.

0 votes
0 answers
1
+1 vote
0 answers
2
0 votes
3 answers
3