Page 345 - Computer science 868 Class 12
P. 345

for(int j = 0; j < n; j++) {
                       this.arr[i] [j] = reverse(p.arr[i] [j]);
                       }
                       }
                       }
                       public void show() {
                       for(int i = 0; i < m; i++) {
                       for(int j = 0; j < n; j++) {
                       System.out.print(arr[i][j] + "\t");
                       }
                       System.out.println();
                       }
                       }
                       public static void main(String args[])throws IOException{
                       Scanner sc = new Scanner(System.in);
                       System.out.print("Enter number of rows::");
                       int x = sc.nextInt();
                       System.out.print("Enter number of columns::");
                       int y = sc.nextInt();
                       MatRev obj1 = new MatRev(x, y);
                       MatRev obj2 = new MatRev(x, y);
                       obj1.fillArray();
                       obj2.revMat(obj1);
                       System.out.println("Original Matrix is::");
                       obj1.show();
                       System.out.println("Matrix with reversed elements");
                       obj2.show();
                       }
                       }
                    7. 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 in Row Major Wise.          [ISC 2019]
                   Ans.  Row Major System Address calculation formula:
                        Address of A [ I ][ J ]  = B + W * [ N * ( I – Lr ) + ( J – Lc ) ]
                                      = 1430 + 4 * [6 * (3 – (-4)) + (6 – 3)]
                                      = 1430 + 4 * [6 * (7) + (3)]
                                      = 1430 + 4 * [42 + 3]
                                      = 1430 + 4 * 45
                                      = 1430 + 180
                                      = 1610
                    8. Two matrices are said to be equal if they have the same dimension and their corresponding elements are equal. For example,
                      the two matrices A and B given below are equal:                                            [ISC 2018]
                            Matrix A                  Matrix B
                         1     2    3              1     2    3
                         2     4    5              2     4    5
                         3     5    6              3     5    6
                       Design a class EqMat to check if two matrices are equal or not. Assume that the two matrices have the same dimension. Some
                      of the members of the class are given below:
                       Class name                             :   EqMat
                       Data Members/Instance variables
                       a[ ][ ]                                :   to store integer elements
                       m                                      :   to store the number of rows
                       n                                      :   to store the number of columns
                       Member Functions/Methods
                       EqMat(int mm, int nn)                  :    parameterised constructor to initialise the data members m = mm and n = nn
                       void readarray()                       :   to enter elements in the array




                                                                                                                       343
                                                                                                              Arrays   343
   340   341   342   343   344   345   346   347   348   349   350