#include<iostream.h>
#include<conio.h>
void Merge(int a[],int m,int b[],int n,int c[])
{
int p1,p2,p3;
p1=p2=p3=0;
while(p1<m&&p2<n)
{
if(a[p1]>b[p2])
c[p3++]=b[p2++];
else
c[p3++]=a[p1++];
}
while(p1<m)
c[p3++]=a[p1++];
while(p2<n)
c[p3++]=b[p2++];
}
void main()
{
clrscr();
int a[50],b[50],c[100],i,n,m;
cout<<"Enter the number of elements for two arrays";
cin>>m>>n;
cout<<"Enter the elements in 1st array";
for(i=0;i<m;i++)
{
cin>>a[i];
}
cout<<"Enter the elements in 2nd array";
for(i=0;i<n;i++)
{
cin>>b[i];
}
Merge(a,m,b,n,c);
cout<<"Element in new array are";
for(i=0;i<(m+n);i++)
{
cout<<c[i]<<",";
}
getch();
}
#include<conio.h>
void Merge(int a[],int m,int b[],int n,int c[])
{
int p1,p2,p3;
p1=p2=p3=0;
while(p1<m&&p2<n)
{
if(a[p1]>b[p2])
c[p3++]=b[p2++];
else
c[p3++]=a[p1++];
}
while(p1<m)
c[p3++]=a[p1++];
while(p2<n)
c[p3++]=b[p2++];
}
void main()
{
clrscr();
int a[50],b[50],c[100],i,n,m;
cout<<"Enter the number of elements for two arrays";
cin>>m>>n;
cout<<"Enter the elements in 1st array";
for(i=0;i<m;i++)
{
cin>>a[i];
}
cout<<"Enter the elements in 2nd array";
for(i=0;i<n;i++)
{
cin>>b[i];
}
Merge(a,m,b,n,c);
cout<<"Element in new array are";
for(i=0;i<(m+n);i++)
{
cout<<c[i]<<",";
}
getch();
}