You are on page 1of 4

/* WRITE A PROGRAM TO IMPLEMENT MERGE OF TWO FILES */ #include <iostream.h> #include <conio.

h> void main() { int m,n,i,j,a[20],b[20],c[20],t,k; clrscr(); cout<<"\n enter the values of m and n="; cin>>m>>n; for(i=0;i<m;i++) { cout<<"\n enter the value of array a="; cin>>a[i]; } for(j=0;j<n;j++) { cout<<"\n enter the value of array b="; cin>>b[j]; } t=m+n; i=0; j=0; k=0; while(i<m&&j<n) { if(a[i]<=b[j])

{ c[k]=a[i]; i++; k++; } else { c[k]=b[j]; j++; k++; } } // end of while loop if(i>=m) { while(j<n) { c[k]=b[j]; k++; j++; } } else if(j>=n) { while(i<m) { c[k]=a[i]; i++; k++;

} } cout<<"\n after merging elements are="; for(i=0;i<t;i++) cout<<"\n"<<c[i]; getch(); } /*********** OUTPUT ************ enter the values of m and n=2 4 enter the value of array a=12 enter the value of array a=34 enter the value of array b=2 enter the value of array b=3 enter the value of array b=5 enter the value of array b=6 after merging elements are= 2 3 5 6

12 34

*/

You might also like