05-02-2011, 02:32 AM
#include <iostream>
#include <iomanip>
using namespace std;
void fill(int[][3]);
void print(int[][3]);
void printa(int[]);
void combine(int[][3],int[][3],int[]);
int main()
{int a[3][3],b[3][3],c[18];
cout"Matrix a\n";
fill(a);
cout"Matrix b\n";
fill(b);
cout"Matrix a\n";
print(a);
cout"Matrix b\n";
print(b);
combine(a,b,c);
cout"The sorted merged array\n";
printa©;
system("pause");
return 0;
}
void printa(int a[])
{int i;
for(i=0;i<18;i++)
coutsetw(4)a[i];
coutendl;
}
void fill(int a[][3])
{int i,j;
cout"Enter the elements of the matrix :\n";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{cout"Enter element ["i"]["j"]: ";
cin>>a[i][j];
}
}
void print(int a[][3])
{int i,j;
for(i=0;i<3;i++)
{for(j=0;j<3;j++)
coutsetw(4)a[i][j];
cout"\n";
}
cout"\n";
}
void combine(int a[][3],int b[][3],int c[])
{bool atemp[3][3]={false};
bool btemp[3][3]={false};
int i,j,upto=0,it,jt,in,max;
for(upto=0;upto<18;upto++)
{
max=-99999;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(!atemp[i][j])
if(a[i][j]>max)
{max=a[i][j];
it=i;
jt=j;
in=0;
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(!btemp[i][j])
if(b[i][j]>max)
{max=b[i][j];
it=i;
jt=j;
in=1;
}
c[upto]=max;
if(in==0)
atemp[it][jt]=true;
else
btemp[it][jt]=true;
}
}
#include <iomanip>
using namespace std;
void fill(int[][3]);
void print(int[][3]);
void printa(int[]);
void combine(int[][3],int[][3],int[]);
int main()
{int a[3][3],b[3][3],c[18];
cout"Matrix a\n";
fill(a);
cout"Matrix b\n";
fill(b);
cout"Matrix a\n";
print(a);
cout"Matrix b\n";
print(b);
combine(a,b,c);
cout"The sorted merged array\n";
printa©;
system("pause");
return 0;
}
void printa(int a[])
{int i;
for(i=0;i<18;i++)
coutsetw(4)a[i];
coutendl;
}
void fill(int a[][3])
{int i,j;
cout"Enter the elements of the matrix :\n";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{cout"Enter element ["i"]["j"]: ";
cin>>a[i][j];
}
}
void print(int a[][3])
{int i,j;
for(i=0;i<3;i++)
{for(j=0;j<3;j++)
coutsetw(4)a[i][j];
cout"\n";
}
cout"\n";
}
void combine(int a[][3],int b[][3],int c[])
{bool atemp[3][3]={false};
bool btemp[3][3]={false};
int i,j,upto=0,it,jt,in,max;
for(upto=0;upto<18;upto++)
{
max=-99999;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(!atemp[i][j])
if(a[i][j]>max)
{max=a[i][j];
it=i;
jt=j;
in=0;
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(!btemp[i][j])
if(b[i][j]>max)
{max=b[i][j];
it=i;
jt=j;
in=1;
}
c[upto]=max;
if(in==0)
atemp[it][jt]=true;
else
btemp[it][jt]=true;
}
}
