#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int ar[100];
int ar2[100];
int arm[100];
int r1,r2,r,i,j,f=0;
for(i=0;i<100;i++)
{
ar[i]=0;
ar2[i]=0;
arm[i]=0;
}
cout<<" Enter the range of two arrays:(less than 100) "<<endl;
cin>>r1>>r2;
cout<<"Enter the elements of the first array:"<<endl;
for(i=0;i<r1;i++)
{
cout<<" Enter element number: "<<(i+1)<<endl;
cin>>ar[i];
}
cout<<" Enter the elements of the second array:"<<endl;
for(i=0;i<r2;i++)
{
cout<<"Enter element number:"<<(i+1)<<endl;
cin>>ar2[i];
}
r=r1+r2;
for(i=0;i<r1;i++)
{
arm[i]=ar[i];
}
for(i=r1;i<r;i++)
{
for(j=0;j<i;j++)
{
if(ar2[i-r1]==arm[j])
{
f=1;
break;
}
}
if(f==0)
arm[i]=ar2[i-r1];
}
cout<<"The elements of merged array is:"<<endl;
for(i=0;i<r;i++)
{
cout<<arm[i];
}
getch();
}
No comments:
Post a Comment