CodesJava

Easy learning with example program codes

CPP program to print Matrix Multiplication


The below program is to print multiplication of two matrices. The CPP cout object is used to output the result on the screen.

Code:

#include <iostream.h>
using namespace std;
 
int main()
{  
int a[2][3] =  
	{  {2, 5, 5}, {4, 0, 6} };
int b[3][2] =  
	{  {4, 5},  {4, 8}, {3, 9}  };
int c[2][2] =  
	{  {0, 0},  {0, 0}  };
int i,j,k;    
int r1 = 2, c1 = 3, c2 = 2;
 
for(i=0; i<r1; i++)    
{    
for(j=0; j<c2; j++)    
{   
for(k=0; k<c1; k++)
c[i][j] += a[i][k] * b[k][j];
}
}
for(i=0; i<r1; i++)    
{    
for(j=0; j<c2; j++)    
cout << c[i][j]<<endl;  
}
return 0;
}

Output

43 
95           
34              
74
Posted in CPP   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki