MERGE TWO ARRAY AND SORT USING C++

# include<iostream.h>
# include<conio.h>
int main()
{
int a[10],b[10],c[30];
int i,j,asize,bsize,temp,csize;
clrscr();
cout<<"\n enter the size of a array\t";
cin>>asize;
cout<<"\n Enter \t"<<asize<<"\telements\n";
for (i=1;i<=asize;i++)
{
  cin>>a[i];
}
cout<<"\n enter the size of B array\t";
cin>>bsize;
cout<<"\n Enter \t"<<bsize<<"\telements\n";
for (i=1;i<=bsize;i++)
{
  cin>>b[i];
}
csize=asize+bsize;
cout<<"\n The A array is\n";
for (i=1;i<=asize;i++)
{
  cout<<a[i]<<"\t";
}
cout<<"\n The B array is\n";
for (i=1;i<=bsize;i++)
{
  cout<<b[i]<<"\t";
}
for(i=1;i<=asize;i++)
{
  c[i]=a[i];
}
j=asize+1;
for(i=1;i<=bsize;i++)
{
  c[j]=b[i];
  j++;
}
cout<<"\n The Merged C array is\n";
for (i=1;i<=csize;i++)
{
  cout<<c[i]<<"\t";
}
// performing sorting
for(i=1;i<=csize;i++)
{
  for(j=i+1;j<=csize;j++)
  {
    if(c[i]>c[j])
    {
temp=c[i];
c[i]=c[j];
c[j]=temp;
    }
  }
}
cout<<"\n sorted array is\n";
for(i=1;i<=csize;i++)
  cout<<c[i]<<"\t";
return(0);
}


No comments:

Post a Comment