Write a C++ program to Merge two given arrays into a third array.
Program Code:
#include<iostream>
using namespace std;
int main()
{
int a[10],b[10],c[20],i;
cout<<"Enter elements in first array : ";
for(i=0;i<5;i++)
{
cin>>a[i];
}
cout<<endl;
cout<<"Enter elements in second array : ";
for(i=0;i<5;i++)
{
cin>>b[i];
}
cout<<endl;
cout<<"Elements of array after merge first and second array : ";
for(i=0;i<5;i++)
{
c[i]=a[i];
c[i+5]=b[i];
}
for(i=0;i<10;i++)
{
cout<<c[i]<<" ";
}
return 0;
}
The program code is tested on www.jdoodle.com
Output:
Enter elements in first array : 1 3 5 2 4
Enter elements in second array : 2 3 4 5 6
Elements of array after merge first and second array : 1 3 5 2 4 2 3 4 5 6
Thanks
Mukesh Rajput
Post A Comment:
0 comments: