matrices problem

Discussion in 'Shell Script' started by harim, Apr 27, 2011.

  1. harim

    harim New Member

    Apr 18, 2011
    Likes Received:
    Trophy Points:
    Problem Statement: Sorting two matrices

    You are required to write a program which takes two 3x3 matrix A and B containing 09 elements each and sort all these 18 elements in descending order and put it in one dimensional array and then display it.

    Follow the following steps to code this program
    1. Take two two-dimensional arrays as A[3][3]and B[3][3] and one-dimensional array C[] to keep the result.
    2. Prompt the user to enter the elements of first matrix
    3. Prompt the user to enter the elements of second matrix
    4. Now take first element of first matrix and check in both matrix weather it is greatest or any other number is the greatest and put the greatest number at the first index of the one dimensional array. Follow this procedure for other elements and at the end one dimensional array would be in descending order
    5. Display this one-Dimensional sorted array on the screen

    Following is the sample program structure

    2 3 5 2 8 7
    A= 6 5 9 B= 0 1 1
    1 0 2 4 7 9

    Output should be like this

    Please enter the Elements of First Matrix:

    Please enter the Elements of second Matrix:

    Sorted Values from Both the Matrices are:
    9 9 8 7 7 6 5 5 4 3 2 2 2 1 1 1 0 0


Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice