Search

# Matrix Multiplication in C++

Matrix is 2D[Dimensional] Array. So here in this program we are going to multiple 2 or more matrix.

Program of Matrix Multiplication in C++

• #include <iostream>

• using namespace std;

• int main()

• {

• int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;

• cout<<"enter the number of row=";

• cin>>r;

• cout<<"enter the number of column=";

• cin>>c;

• cout<<"enter the first matrix element=\n";

• for(i=0;i<r;i++)

• {

• for(j=0;j<c;j++)

• {

• cin>>a[i][j];

• }

• }

• cout<<"enter the second matrix element=\n";

• for(i=0;i<r;i++)

• {

• for(j=0;j<c;j++)

• {

• cin>>b[i][j];

• }

• }

• cout<<"multiply of the matrix=\n";

• for(i=0;i<r;i++)

• {

• for(j=0;j<c;j++)

• {

• mul[i][j]=0;

• for(k=0;k<c;k++)

• {

• mul[i][j]+=a[i][k]*b[k][j];

• }

• }

• }

• //for printing result

• for(i=0;i<r;i++)

• {

• for(j=0;j<c;j++)

• {

• cout<<mul[i][j]<<" ";

• }

• cout<<"\n";

• }

• return 0;

• }

Output â€“

enter the number of row=3

enter the number of column=3

enter the first matrix element=

1 2 3

1 2 3

1 2 3

enter the second matrix element=

1 1 1

2 1 2

3 2 1

multiply of the matrix=

14 9 8

14 9 8

14 9 8

For Video Tutorials Subscribe our Youtube Channel

---------------------------------------------------------------------------------------------------------------------------

Previous Page Next Page

Any Doubt ? Feel free to write a comment

Download C++ Projects

Join us on LinkedIn â€“ Great Place of Networking

Follow us on More Together â€“ Facebook for regular updates

Mandatory to join Telegram group for regular job updates

Mandatory to join whatsapp group for regular job updates

Other C++ Programs

For Other Tutorials â€“ Click Here

Tags:

2 views0 comments

### Related Posts

See All

#### Number to Character Conversion in C++

Program to implement Number to Character Conversion in C++ Firstly see what we are going to do ? Like this 0 - zero 1 â€“ one 2 â€“ two 3 â€“ three 4 â€“ four 5 â€“ five 6 â€“ six 7 â€“ seven 8 â€“ eight 9 â€“ nine How

#### Factorial of a number in C++

In this tutorial we are going to see how to find a factorial of number using C++ program Firstly letâ€™s see a example to understand it better n! = n + (n-1) + (n-2) ! n>=1 3! = 3 *2*1 = 6 Program to fi

#### Fibonacci Triangle in C++

Program to implement Fibonacci Triangle in C++ #include <iostream> using namespace std; int main() { int a=0,b=1,i,c,n,j; cout<<"Enter the limit: "; cin>>n; for(i=1; i<=n; i++) { a=0; b=1; cout<<b<<"\