Javatpoint Logo
Javatpoint Logo

Matrix Calculator in C

Matrix-based issue solving requires extensive computation labor, and if even one error is made, the user will not be able to obtain the desired answer. For each row and column, you must input the required components. It is not enough to just enter data for each individual index to fix the issue. It takes a lot of effort to acquire the output and perform the processing steps necessary to reach the desired outcome. By removing the values from other indices, you may get the centre value.

Each member of the second matrix must be multiplied by every other element when performing multiplication. Each row element of the first matrix is multiplied by each column member of the second matrix as part of the processing activity.

It will take some time to manually solve this problem, and the amount of time will also depend on the type of matrix. It is simple to solve the problem within five minutes if the matrix size is 2x2, but more challenging if the index size is larger than 3 or the matrix indexes differ. Therefore, to save time, you can use this method to match your solutions by just providing a few parameters regarding the type of matrix and its components.

Current Scenario

Although the current system also offers computer-oriented approaches to obtain the results of matrix multiplications, the current method cannot be used to varied sizes. This system can only be used for matrix whose index sizes are of two dimensions, and it cannot be used for matrix whose index sizes vary. Additionally, you will be able to compute the multiplication of two 2x2 matrix matrices. However, you won't be able to verify your findings simultaneously since matrices larger than 2 cannot be used to generate results. In order to allow users to double-check their submitted data, the current system is also unable to show the entered elements while presenting the final results.

Problem this project will solve

Any required matrix size may be produced using the existing matrix multiplication technology. Before inputting the element values for a given matrix, users will additionally have the option of selecting the matrix size. You only need to enter the elements for each matrix after the matrix sizes for both matrices have been entered. With this technique, you won't need to put in any further effort because the login listed on the screen's reverse side will handle the remaining tasks. It will be able to show both the final results and specifics from each matrix.

Program Breakdown

In our Program we are declaring user defined functions like to read the matrix we have read matrix function, to prirnt matrix we have printMatrix function, to add and subtract the matrix we have matrixAddSub function, to multiply we have matrixScalarMultipy function.

In the main function of our program we have different options for user to perform like to add, to subtract, to scalar multiply, to multiply two matrices.

If the user has chosen any option then the system will ask to add the elements of the 2 matrices to be added in all cases.

The above function readMatrix will read the matrix elements entered by the user.

The above function will print the matrix entered by the user.

If the user has selected the option to add then the above function will come in action and add the elements of the 2 matrices.

If the user has selected the option to scalar multiply then the above function will come in action.

If the user has selected the option to multiply then the above function will come in action and multiply the elements of the 2 matrices and print the result.

Program for Matrix Calculator in C++

Output:

Operation Menu
        1. to Add
        2. to Subtract
        3. to Scalar Multiply        
        4. to Multiply two matrices
Enter your choice: 1

Enter the #rows and #cols for matrix A: 2 2
Enter the #rows and #cols for matrix B: 2 2

        Enter elements of Matrix A a 2 x 2 matrix.
        2 entries for row 1: 1 2
        2 entries for row 2: 3 4
   Matrix A

        1       2
        3       4

        Enter elements of Matrix B a 2 x 2 matrix.
        2 entries for row 1: 5 6
        2 entries for row 2: 7 8
  Matrix B

        5       6
        7       8

The Sum of matrixA + matrixB is :
        6       8
        10      12
Do you want to calculate again? Y/N
Y
Enter your choice: 2

Enter the #rows and #cols for matrix A: 2 2
Enter the #rows and #cols for matrix B: 2 2

        Enter elements of Matrix A a 2 x 2 matrix.
        2 entries for row 1: 1 2
        2 entries for row 2: 3 4

                Matrix A

        1       2
        3       4

        Enter elements of Matrix B a 2 x 2 matrix.
        2 entries for row 1: 5 6
        2 entries for row 2: 7 8

                Matrix B

        5       6
        7       8

The difference between matrixA - matrixB is :
        -4      -4
        -4      -4
Do you want to calculate again? Y/N
Y
Enter your choice: 3

Enter the scalar: 2

The scalar is: 2
Enter the #rows and #cols for matrix A: 2 2

        Enter elements of Matrix A a 2 x 2 matrix.
        2 entries for row 1: 1 2
        2 entries for row 2: 3 4

                Matrix A

        1       2
        3       4

The scalar multiplication between matrixA * 2 is:
2       4
6       8
Enter your choice: 4

Enter the #rows and #cols for matrix A: 2 2
Enter the #rows and #cols for matrix B: 1 2

Error! column of first matrix not equal to row of second.
Enter the #rows and #cols for matrix A: 1 2
Enter the #rows and #cols for matrix B: 3 4
Error! column of first matrix not equal to row of second.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA