#include<iostream.h>
#include<conio.h>
#define max 10
void in_mat(int[max][max],int,int);
void disp_mat(int[max][max],int,int);
void mul_mat(int[max][max],int[max][max],int[max][max],int,int,int);
void main()
{
int x[max][max],y[max][max],z[max][max],a,b,c,d;
clrscr();
do
{
cout<<"\n\n Enter the numbers of rows n columns of matrix #1 : ";
cin>>a>>b;
cout<<"\n\n Enter the numbers of rows n columns of matrix #2 : ";
cin>>c>>d;
if ( b != c )
cout<<"\n\n Matrices can't be multiplied .. !! ";
}while( b != c );
cout<<"\n\n Now, The Matrices can be multiplied .. !! ";
getch();
cout<<"\n\n\n\n Enter the elements for the following matrices \n";
cout<<"\n\n Enter for the Matrix #1 \n";
in_mat(x,a,b);
cout<<"\n\n Enter for the Matrix #2 \n";
in_mat(y,c,d);
clrscr();
cout<<"\n\n The following matrices are : ";
cout<<"\n\n\t\t Matrix #1 :- ";
disp_mat(x,a,b);
cout<<"\n\n\t\t Matrix #2 :- ";
disp_mat(y,c,d);
mul_mat(x,y,z,a,d,b);
cout<<"\n\n\t The Product of the above two matrices are \n";
disp_mat(z,a,d);
getch();
}
void in_mat(int mat[max][max],int row,int col)
{
int i,j;
for(i=0;i<row;i++)
{
cout<<"\n Enter its elements for Row #"<<i+1<<" : ";
for(j=0;j<col;j++)
cin>>mat[i][j];
}
}
void disp_mat(int mat[max][max],int row,int col)
{
int i,j;
for(i=0;i<row;i++)
{
cout<<"\n\t Row #"<<i+1<<" :";
for(j=0;j<col;j++)
cout<<" "<<mat[i][j];
}
}
void mul_mat(int mat1[max][max],int mat2[max][max],int mat3[max][max],int r1,int c2,int r2c1)
{
int i,j,k;
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
mat3[i][j] = 0;
for(k=0;k<r2c1;k++)
mat3[i][j] += mat1[i][k] * mat2[k][j];
}
}
}
#include<conio.h>
#define max 10
void in_mat(int[max][max],int,int);
void disp_mat(int[max][max],int,int);
void mul_mat(int[max][max],int[max][max],int[max][max],int,int,int);
void main()
{
int x[max][max],y[max][max],z[max][max],a,b,c,d;
clrscr();
do
{
cout<<"\n\n Enter the numbers of rows n columns of matrix #1 : ";
cin>>a>>b;
cout<<"\n\n Enter the numbers of rows n columns of matrix #2 : ";
cin>>c>>d;
if ( b != c )
cout<<"\n\n Matrices can't be multiplied .. !! ";
}while( b != c );
cout<<"\n\n Now, The Matrices can be multiplied .. !! ";
getch();
cout<<"\n\n\n\n Enter the elements for the following matrices \n";
cout<<"\n\n Enter for the Matrix #1 \n";
in_mat(x,a,b);
cout<<"\n\n Enter for the Matrix #2 \n";
in_mat(y,c,d);
clrscr();
cout<<"\n\n The following matrices are : ";
cout<<"\n\n\t\t Matrix #1 :- ";
disp_mat(x,a,b);
cout<<"\n\n\t\t Matrix #2 :- ";
disp_mat(y,c,d);
mul_mat(x,y,z,a,d,b);
cout<<"\n\n\t The Product of the above two matrices are \n";
disp_mat(z,a,d);
getch();
}
void in_mat(int mat[max][max],int row,int col)
{
int i,j;
for(i=0;i<row;i++)
{
cout<<"\n Enter its elements for Row #"<<i+1<<" : ";
for(j=0;j<col;j++)
cin>>mat[i][j];
}
}
void disp_mat(int mat[max][max],int row,int col)
{
int i,j;
for(i=0;i<row;i++)
{
cout<<"\n\t Row #"<<i+1<<" :";
for(j=0;j<col;j++)
cout<<" "<<mat[i][j];
}
}
void mul_mat(int mat1[max][max],int mat2[max][max],int mat3[max][max],int r1,int c2,int r2c1)
{
int i,j,k;
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
mat3[i][j] = 0;
for(k=0;k<r2c1;k++)
mat3[i][j] += mat1[i][k] * mat2[k][j];
}
}
}
No comments:
Post a Comment