Page 460 - computer science (868) class 11
P. 460

Program 9      Write a program to declare a matrix A[ ][ ] of order (m*n) where 'm' is the number of rows and 'n'
                               is the number of columns such that both m and n must be greater than 2 and less than 20.
                               Allow the user to input positive integers into this matrix. Perform the following tasks on the
                               matrix:
                               (a)   Sort the elements of the outer row and column in ascending order using any standard
                                   sorting technique.
                               (b)  Calculate the sum of the outer row and column elements.
                               (c)   Output the original matrix, rearranged matrix, and only the boundary elements of the
                                   rearranged array with their sum.
                               Test your program for the following data and some random data.
                               Example:
                                   INPUT : M=3, N=3
                                   1 7 4
                                   8 2 5
                                   6 3 9
                                   OUTPUT:
                                   ORIGINAL MATRIX:

                                   1 7 4
                                   8 2 5
                                   6 3 9
                                   REARRANGED MATRIX:
                                   1 3 4
                                   9 2 5
                                   8 7 6
                                   BOUNDARY ELEMENTS:
                                   1 3 4
                                   9     5
                                   8 7 6

                                   SUM OF OUTER ROW AND OUTER COLUMN = 43

                 1       import java.util.*;

                 2       class prog7
                 3       {

                 4           public static void main(String args[])
                 5           {

                 6               Scanner sc=new Scanner(System.in);
                 7               int s=0;

                 8                System.out.println("Enter the number of rows and columns(>2 and <20) : ");
                 9               int m=sc.nextInt();





                458458  Touchpad Computer Science-XI
   455   456   457   458   459   460   461   462   463   464   465