┬аfor (j=0; j=60)&&(A[1] [j)<=600))
┬аA[i][j]/=6
OR
A[i] [j] =A[i] [j] /6;
┬а}
Question - 9 : - A two dimensional array P[20] [50] is stored in the memory along the row with each of its element occupying 4 bytes, find the address of the element P[10] [30], if the element P[5] [5] is stored at the memory location 15000.
Answer - 9 : -
Loc (P [I] [J] along the row =BaseAddress+W [(I-LBR)*C+ (J-LBC)]
(where C is the number of columns, LBR = LBC =0)
LOC (P [5] [5]) = BaseAddress + W* [I*C + J]
15000 = BaseAddress + 4 * [5 * 50 + 5]
= BaseAddress + 4 * [250 + 5]
= BaseAddress + 4*255 = BaseAddress + 1020
BaseAddress = 15000 -1020 = 13980
LOC (P [10] [30]) = 13980 + 4* [10 * 50 + 30]
= 13980 + 4 * 530
= 13980 + 2120
= 16100
OR LOC (P [10] [30])
= Loc (P[5] [5]) + W[ (I-LBR) * C+ (J-LBC)]
= 15000 + 4 [(10 тАУ 5) * 50 + (30 тАУ 5)]
= 15000 + 4 [5 * 50 + 25]
= 15000 + 4 *275
= 15000 + 1100
= 16100
OR
(where C is the number of columns and LBR = LBC = 1)
LOC (P [5] [5])
15000 = BaseAddress + W [(I-1) *C + (J-1)]
= BaseAddress + 4 [4*50 + 4]
= BaseAddress + 4 [200 + 4]
= BaseAddress + 4 * 204
= BaseAddress + 816
BaseAddress = 15000 тАУ 816 = 14184
LOC (P [10] [30])
= 14184 + 4 [(10 -1) * 50 + (30 -1)]
= 14184 + 4 [9*50 + 29]
= 14184 + 4*479
= 14184 + 1916
= 16100
Question - 10 : - Write a user-defined function DisTen (int A[] [4], int N, int M) in C++ to find and display all the numbers, which are divisible by 10. For example if the content of array is :
12 20 13
2 10 30
The output should be
20 10 30
Answer - 10 : -
void DisTen (int A[] [4] , int N, int M)
┬а{
┬аint i, j;
┬аfor (i=0; i
┬а{
┬аfor (j = 0 ; j
┬а{
┬аif (A[i][j]%10==0)
┬аcout << A [i] [ j] ;
┬а}
┬а}
┬а}