3x3 matrix multiplication in c++

#include <iostream>
using namespace std;

int main()
{
    int a[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, i, j, k;

    cout << "Enter rows and columns for first matrix: ";
    cin >> r1 >> c1;
    cout << "Enter rows and columns for second matrix: ";
    cin >> r2 >> c2;

    // If column of first matrix in not equal to row of second matrix,
    // ask the user to enter the size of matrix again.
    while (c1!=r2)
    {
        cout << "Error! column of first matrix not equal to row of second.";

        cout << "Enter rows and columns for first matrix: ";
        cin >> r1 >> c1;

        cout << "Enter rows and columns for second matrix: ";
        cin >> r2 >> c2;
    }

    // Storing elements of first matrix.
    cout << endl << "Enter elements of matrix 1:" << endl;
    for(i = 0; i < r1; ++i)
        for(j = 0; j < c1; ++j)
        {
            cout << "Enter element a" << i + 1 << j + 1 << " : ";
            cin >> a[i][j];
        }

    // Storing elements of second matrix.
    cout << endl << "Enter elements of matrix 2:" << endl;
    for(i = 0; i < r2; ++i)
        for(j = 0; j < c2; ++j)
        {
            cout << "Enter element b" << i + 1 << j + 1 << " : ";
            cin >> b[i][j];
        }

    // Initializing elements of matrix mult to 0.
    for(i = 0; i < r1; ++i)
        for(j = 0; j < c2; ++j)
        {
            mult[i][j]=0;
        }

    // Multiplying matrix a and b and storing in array mult.
    for(i = 0; i < r1; ++i)
        for(j = 0; j < c2; ++j)
            for(k = 0; k < c1; ++k)
            {
                mult[i][j] += a[i][k] * b[k][j];
            }

    // Displaying the multiplication of two matrix.
    cout << endl << "Output Matrix: " << endl;
    for(i = 0; i < r1; ++i)
    for(j = 0; j < c2; ++j)
    {
        cout << " " << mult[i][j];
        if(j == c2-1)
            cout << endl;
    }

    return 0;
}

3
1

                                    3 3 3
3 3 3

3 (1 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
matrix multiplication code c++ c++ comute matrxi multiplication multidimensional arrays C++multiplication matmult will run by being given the dimensions of the two arrays to multiply together. These 4 values will be read as command-line arguments in c++ matrix multiplication in c++ using 2d array usual multiplication matrix 3 x 3 c++ multiplication matrices c++ write a c++ program to multiply two 3*3 matrix using multidimensional arrays understand matrix multiplication using c++ matrix mult cpp matrix multiplication algo in c++ c++ multiply matrix c++ matrix code multiplication of matrices c++ code multiplication of 2*2 matrix in c++ Write a program, which take input of two matrix from user on console (M1 of size 2x3) and M2 of (size 3x2) calculate matrix multiplication of 2x2 in cpp calculate matrixmultiplication of 2x2 in cpp multiplication of matrix c++ matrix multipliactiom c++ c++ function for matrix multiplication c++ code for 2d array multiplication Program to Multiply two Matrices without using functions. array multiplication c++ matrix multiplication code in c++ print 4x2 matrix in c++ 3x3 matrix multiplication in c++ Write a program in C to Scan two matrices (of appropriate order).Pass these to a function. Function should multiply these two matrices Write a program in C to Scan two matrices (of appropriate order).Pass these to a function. Function should multiply these two matrices and return the result to the main function. Display the result in main function. c plus plus program to multiply two matridx multiplication of matrices c++ C++ matrix multiplication function Write a program to get a 5X5 matrices from user and get its vertex elements in c++ array multiplication in cpp multiplication of matrices in c++ code for matrix multiplication in cpp Program for implementing multiplication of two matrices in cpp matrix in cpp multiplying two matrix in cpp multiplying matricies c++ multiplication of matrix in c++ Write a C++ program to implement multiplication of 2D arrays matrix multiplication using multidimensional array in C++ 2d array multiplication c++ multiplication of matrices in c++ using 2d arrays multiply matrices where n is entered by user c++ multiply two square matrices in c++ c++ code for matrix multiplication Write a complete C++ program to multiply two 2D matrices. Program should have code to check for multiplication rule. multiply 2d vector matrices c++ how to perform matrix multiplication in c++ c++ matrix multiplication matrix multiplication program in c++ using class and object taking input from user c++ program for multiplication of two 2d matrices C++ Program to Multiply Two Matrix Using Multi-dimensional Arrays and pointer c++ multiply of matrix multiplying matrices c++ matrix multiplication and division in c++ multiplying two rows of. matric in cpp matrix multiplication in cpp multiplication of matrix in c++ using class multiplication of two matrix in c++ product of 2 matrices in c++ c++ std matrix multiplication w.a.p in c++ to overload * operator which multiply two matrix objects. w.a.p in c++ to calculate A intersection B where A and B are both array cpp multiply 2 different sized matrix c++ matrix multiplcation matrix multiplying c++ matrix multiplication cpp C++ Program to element wise Multiply Two Matrix Using Multi-dimensional Arrays np.multiply in cpp code multiply matrix cpp c++ multiplication matrix multiplication of matrices cpp matrix multiplication in c+ matrix multiplication of 2*2 matrix in c++ matrix multiplication of 2*2 matrix in c++ using constructor cpp matrix multiplication matrix multiplication coding c++ program for matrix multiplication c++ matrix multiplication in c++ matrix multiplications in c++ matrix multiplication c++ Write C/C++ program for storing matrix. Write functions for d) Add, subtract and multiply two matrices with exception handling
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source