Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use C++ language Use C++ language Use C++ language Use C++ language Use C++ lang

ID: 3843447 • Letter: U

Question

Use C++ language

Use C++ language

Use C++ language

Use C++ language

Use C++ language

Use C++ language

Use C++ language

MATRICES REQUIREMENTS: Many mathematical problems require the addition, subtraction, and multiplication of two matrices. Although matrices are often stored as arrays, it is also possible to represent them as list structures. For example, the matrix 3040 5 0 0 2 0 1 1 0 0 0 2 0 0 0 0 0 This can be represented as a sorted list of triples as shown below row column value This implementation is a particularly useful technique for sparse matrices; that is, matrices with many zero elements SPEFICIFATIONS: Design and implement a program that maintains a list of l0 sparse matrices. Your program must process the commands described below. You may detemine the details of the user interface; it must be relatively "friendly" and usable. For all of the operations defined below,

Explanation / Answer

#include<stdio.h>

int main()

{

    // Assume 4x5 sparse matrix

    int sparseMatrix[4][5] =

    {

        {3 , 0 ,4 , 0 , 5 },

        {0 , 0 , 2 , 0 , 1 },

        {1 , 0 , 0 , 0 , 2 },

        {0 , 0 , 0 , 0 , 0 }

    };

    int size = 0;

    for (int i = 0; i < 4; i++)

        for (int j = 0; j < 5; j++)

            if (sparseMatrix[i][j] != 0)

                size++;

  

    int compactMatrix[3][size];

    // Making of new matrix

    int k

    for (i = 0; i < 4; i++)

        for (j = 0; j < 5; j++)

            if (sparseMatrix[i][j] != 0)

            {

                compactMatrix[0][k] = i;

                compactMatrix[1][k] = j;

                compactMatrix[2][k] = sparseMatrix[i][j];

                k++;

            }

    for (i=0; i<3; i++)

    {

        for (j=0; j<size; j++)

            printf("%d ", compactMatrix[i][j]);

        printf(" ");

    }

    return 0;

}

#include<stdio.h>

int main()

{

    // Assume 4x5 sparse matrix

    int sparseMatrix[4][5] =

    {

        {3 , 0 ,4 , 0 , 5 },

        {0 , 0 , 2 , 0 , 1 },

        {1 , 0 , 0 , 0 , 2 },

        {0 , 0 , 0 , 0 , 0 }

    };

    int size = 0;

    for (int i = 0; i < 4; i++)

        for (int j = 0; j < 5; j++)

            if (sparseMatrix[i][j] != 0)

                size++;

  

    int compactMatrix[3][size];

    // Making of new matrix

    int k

    for (i = 0; i < 4; i++)

        for (j = 0; j < 5; j++)

            if (sparseMatrix[i][j] != 0)

            {

                compactMatrix[0][k] = i;

                compactMatrix[1][k] = j;

                compactMatrix[2][k] = sparseMatrix[i][j];

                k++;

            }

    for (i=0; i<3; i++)

    {

        for (j=0; j<size; j++)

            printf("%d ", compactMatrix[i][j]);

        printf(" ");

    }

    return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote