C++ Program – Merge two Arrays
by Nideesh C on May 2, 2011 · 0 comments
in C++
//Downloaded From theonlinetutorials.com
//(C)2011.All rights reserved.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int k=0,i,na,nb,j,a[50],b[50],c[50];
cout<<"Enter A lim"<<endl;
cin>>na;
cout<<"Enter B lim"<<endl;
cin>>nb;
cout<<"Enter A ele";
for(i=0;i<na;i++)
cin>>a[i];
cout<<"Enter B ele"<<endl;
for(j=0;j<nb;j++)
cin>>b[j];
j=0;
i=na-1;
cout<<"Processing";
while((i>=0)&&(j<nb))
{
if((b[j]<a[i]))
{
c[k]=a[i];
i--;
k++;
}
if((b[j]>a[i]))
{
c[k]=b[j];
j++;
k++;
}
if((b[j]==a[i]))
{
c[k]=b[j];
j++;
k++;
c[k]=a[i];
i--;
k++;
}
}
if(i==-1)
{
while(j<nb)
{
c[k]=b[j];
j++;
k++;
}
}
else if(j==nb)
{
while(i>=0)
{
c[k]=a[i];
i--;
k++;
}
}
cout<<"The New Array is"<<endl;
for(k=0;k<na+nb;k++)
cout<<c[k]<<endl;
getch();
}
Not Satisfied ? Just search & get the result
Related posts:
- C++ Program – Insert & Delete an element from array
- C++ Program – BUBBLE SELECTION SORT
- C++ rogram to implement merge sort
- C++ Program – Insert Delete from 1-D array
- C Program to find the perfect numbers below a given number.
Tagged as:
C++ Program - Merge two Arrays,
CPP Program - Merge two Arrays,
Merge two Arrays,
Merge two Arrays in C++,
Merge two Arrays in CPP
Me, freelance system administrator having the qualification of Diploma in Electronics & Tele-communication + MCSE + CCNA + CST + 5 years of experience in IT field.
If you like This post, you can follow TheOnlineTutorials on Twitter.
Contact me Via email: support@theonlinetutorials.com
Subscribe to feed via Feed or EMAIL to receive instant updates.
Legal Disclaimer:All information found on the site is without any implied warranty of fitness for any purpose or use whatsoever. Content author/site administrator is not responsible for any loss occurred due to mistakes in this tutorial. Use this tutorial website at your own risk.