#include<stdio.h> //header file
#include<conio.h> //header file
void main() //starting of the main() function
{
int j=0,k=0,p,n,m,i,a[10],b[15],c[25]; //declaration of the variables
clrscr();
printf("program that merge two sorted arrays");
printf("\n\n\n\t\t------------INPUT-------------");
printf("\n\nenter the length of the first array");//taking input from the user
scanf("%d",&n);
printf("\nenter the length of the second array");//taking input from the user
scanf("%d",&m);
printf("\n\nenter the elements in the sorted form into first array");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nenter the elements in the sorted form into second array");
for(i=0;i<m;i++)
scanf("%d",&b[i]);
for(p=0;j<n && k<m;p++)
{
if(a[j]<b[k])
{
c[p]=a[j];
j++;
}
else
{
c[p]=b[k];
k++;
}
}
if(j<n)
{
while(j<n)
{
c[p]=a[j];
j++;
p++;
}
}
if(k<m)
{
while(k<m)
{
c[p]=b[k];
k++;
p++;
}
}
printf("\n\n\n\t\t------------OUTPUT------------");
printf("\n\nthe elements merged into the third array are=");
printf("\n\n\t");
for(i=0;i<p;i++)//printing output
printf("%d ",c[i]);
getch();
}