Hi everyone!!!
At times multiplication of matrix using C++ program is very tricky. The logic which leads to the result is very difficult to derive using looping. So here is the program coding for the multiplication of two 3 X 3 matrices.
Enjoy!!!
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int a[3][3],b[3][3],c[3][3];
int i,j;
cout<<"\n\nEnter the elements of A matrix : \n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
a[i][j] =0;
cout<<"\nEnter A["<<i<<"]["<<j<<"] : ";
cin>>a[i][j];
}
}
cout<<"\n\nEnter the elements of A matrix : \n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j] =0;
cout<<"\nEnter B["<<i<<"]["<<j<<"] : ";
cin>>b[i][j];
}
}
clrscr();
cout<<"\n\nThe matrix A is \n\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<'\t'<<a[i][j];
}
cout<<endl;
}
cout<<"\n\nThe matrix B is \n\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<'\t'<<b[i][j];
}
cout<<endl;
}
cout<<"\n\nThe multiplication of the two matrices is \n\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j] =0;
c[i][j]=(a[i][0]*b[0][i])+(a[i][1]*b[1][i])+(a[i][2]*b[2][j]);
cout<<'\t'<<c[i][j];
}
cout<<endl;
}
getch();
}
At times multiplication of matrix using C++ program is very tricky. The logic which leads to the result is very difficult to derive using looping. So here is the program coding for the multiplication of two 3 X 3 matrices.
Enjoy!!!
SNAPSHOTS
CODING
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int a[3][3],b[3][3],c[3][3];
int i,j;
cout<<"\n\nEnter the elements of A matrix : \n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
a[i][j] =0;
cout<<"\nEnter A["<<i<<"]["<<j<<"] : ";
cin>>a[i][j];
}
}
cout<<"\n\nEnter the elements of A matrix : \n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j] =0;
cout<<"\nEnter B["<<i<<"]["<<j<<"] : ";
cin>>b[i][j];
}
}
clrscr();
cout<<"\n\nThe matrix A is \n\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<'\t'<<a[i][j];
}
cout<<endl;
}
cout<<"\n\nThe matrix B is \n\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<'\t'<<b[i][j];
}
cout<<endl;
}
cout<<"\n\nThe multiplication of the two matrices is \n\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j] =0;
c[i][j]=(a[i][0]*b[0][i])+(a[i][1]*b[1][i])+(a[i][2]*b[2][j]);
cout<<'\t'<<c[i][j];
}
cout<<endl;
}
getch();
}
viewers please do comment your feedback. also of u need any other code comment. i will post shortly
ReplyDelete