Aim: - To merge two sorted array
into one sorted array.
#include<stdio.h>
#include<conio.h> void main()
{
int a[10],b[10],c[20],i,j,k,n,m,t;
clrscr();
printf("Enter size of Array A\n"); scanf("%d",&n);
printf("Enter the data in Array A\n"); for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter size of Array B\n"); scanf("%d",&m);
printf("Enter the data in Array B\n"); for(j=0;j<m;j++)
{
scanf("%d",&b[j]);
}
i=j=k=0; while(i<n&&j<m)
{
if(a[i]<b[j])
c[k++]=a[i++];
else if(a[i]>=b[j])
c[k++]=b[j++];
if(i<n)
{
for(t=0;t<m;t++)
c[k++]=b[j++];
}
else
{
for(t=0;t<n;t++)
c[k++]=a[i++];
printf("\n"); for(k=0;k<(m+n);k++) printf("\n %d ",c[k]);
getch();
}