Saturday, 1 September 2012

Multiplication of two 2D Matrix

Guys Hello !! Here is Code in C++ for multiplying two 2D Matrix. It is not the tough as you consider it till now .

















Multiplication on Two matrix a[2][2]*b[2][2]
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
int a[10][10];int b[10][10];int c[10][10];
void main()
{
int i,j,k,l;
clrscr();


cout<<"Enter the value of the matrix a:";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>a[i][j];
}
}
cout<<"\n Enter the value of the matrix b:";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>b[i][j];
}
}


cout<<"\n The multiplied value is:";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=0;
for(k=0;k<2;k++)
{
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<c[i][j];
}
cout<<"\n" ;
}

getch();
}


OUTPUT:

6 comments: