To know about 'class' click here
#include<iostream.h>
#include<conio.h>
class matrix
{
int a[10][10];
int m,n;
public:
void input();
void output();
void multiply(matrix,matrix);
};
void matrix::input()
{
cout<<"Enter the number of row : ";
cin>>m;
cout<<"Enter the number of column : ";
cin>>n;
cout<<"Matrix"<<"\n";
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
}
void matrix :: output()
{
for(int i=0;i<m;i++)
{
cout<<"\n";
for(int j=0;j<n;j++)
{
cout<<a[i][j]<<"\t";
}
}
}
void matrix :: multiply(matrix m1, matrix m2)
{
if(m1.n!=m2.m)
{
cout<<"matrix multiplication is not possible";
}
else
{
for(int i=0;i<m1.m;i++)
{
for(int j=0;j<m2.n;j++)
{
a[i][j]=0;
for(int k=0;k<m1.n;k++)
{
a[i][j]=a[i][j] +( m1.a[i][k]*m2.a[k][j]);
m=m1.m;
n=m2.n;
}
}
}
}
}
void main()
{
clrscr();
matrix m1,m2,m3;
m1.input();
m2.input();
m3.multiply(m1,m2);
m3.output();
getch();
}
#include<iostream.h>
#include<conio.h>
class matrix
{
int a[10][10];
int m,n;
public:
void input();
void output();
void multiply(matrix,matrix);
};
void matrix::input()
{
cout<<"Enter the number of row : ";
cin>>m;
cout<<"Enter the number of column : ";
cin>>n;
cout<<"Matrix"<<"\n";
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
}
void matrix :: output()
{
for(int i=0;i<m;i++)
{
cout<<"\n";
for(int j=0;j<n;j++)
{
cout<<a[i][j]<<"\t";
}
}
}
void matrix :: multiply(matrix m1, matrix m2)
{
if(m1.n!=m2.m)
{
cout<<"matrix multiplication is not possible";
}
else
{
for(int i=0;i<m1.m;i++)
{
for(int j=0;j<m2.n;j++)
{
a[i][j]=0;
for(int k=0;k<m1.n;k++)
{
a[i][j]=a[i][j] +( m1.a[i][k]*m2.a[k][j]);
m=m1.m;
n=m2.n;
}
}
}
}
}
void main()
{
clrscr();
matrix m1,m2,m3;
m1.input();
m2.input();
m3.multiply(m1,m2);
m3.output();
getch();
}
Why this program show cout is not declared
ReplyDeletetype "using namespace std;" below #include
DeleteWhy this program show cout is not declared
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteTabahi.....
ReplyDeleteu are coding better and simple not complex
ReplyDeletebkbas
ReplyDeletem=m1.m;
ReplyDeleten=m2.n;
Could you please let me kno wwhy this part comes in multiply funtion