Page 311 - Computer science 868 Class 12
P. 311

6.   A matrix ARR[- 4…6, 3….8] is stored in the memory with each element requiring 4 bytes of storage. If the base
                      address is 1430, find the address of ARR[3][6] when the matrix is stored row major wise.
                   7.   A square matrix A[mxm] is stored in the memory with each element requiring 2 bytes of storage. If the base
                      address A[1][1] is 1098 and the address at A[4][5] is 1144, determine the order of the matrix A[mxm] when the
                      matrix is stored column major wise.
                   8.   A matrix A[m][n] is stored with each element requiring 4 bytes of storage. If the base address at A[1][1] is 1500
                      and the address at A[4][5] is 1608, determine the number of rows of the matrix when the matrix is stored
                      column major wise.
                   9.   The array D[-2…10][3…8] contains double type elements. If the base address is 4110, find the address of D[4][5],
                      when the array is stored column major wise.
                   10.   A square matrix M[][] of size 10 is stored in the memory with each element requiring 4 bytes of storage. If the
                      base address is M[0][0] of 1840, determine the address at M[4][8] when the matrix is stored row major wise.



                  Some More Programs



                   Program 1     Write a Java program to rotate an array by n elements. Given an array of integers, circularly
                                 rotate the elements of the array, by a given value, say n.
                                 Example:
                                 int array[] = {1,2,3,4,5}
                                 n = 3
                                 output = {3,4,5,1,2}
                   1        import java.util.*;

                   2        class Arr_rotate
                   3        {

                   4            public static void rotate(int ar[], int n)
                   5            {
                   6                int i,j,temp,temp1;

                   7                for(i=1;i<=n;i++)

                   8                {
                   9                    temp = ar[0];
                   10                   for(j=0;j<ar.length;j++)

                   11                   {
                   12                       temp1 = ar[(j+1) % ar.length];

                   13                       ar[(j+1) % ar.length] = temp;
                   14                       temp = temp1;

                   15                   }
                   16               }

                   17           }





                                                                                                                       309
                                                                                                              Arrays   309
   306   307   308   309   310   311   312   313   314   315   316