#include<stdio.h>
int main()
{
int a[100],b[100],n,m,i,j,c[100],k=0;
printf("Enter the size of first array: ");
scanf("%d",&m);
printf("Enter the elements in first array in ascending order: ");
for(i=0; i<m; i++)
{
scanf("%d",&a[i]);
}
printf("Enter the size of second array: ");
scanf("%d",&n);
printf("Enter the elements in second array: ");
for(j=0; j<n; j++)
{
scanf("%d",&b[j]);
}
i=0;
j=0;
while(i<m&&j<n)
{
if(a[i]<b[j])
{
c[k]=a[i];
k++;
i++;
}
else
{
c[k]=b[j];
k++;
j++;
}
}
while(i<m)
{
c[k]=a[i];
k++;
i++;
}
while(j<n)
{
c[k]=b[j];
k++;
j++;
}
printf("The simple merge sorted array is: ");
for(k=0; k<m+n; k++)
{
printf("%d\t",c[k]);
}
return 0;
}
Note: Need to be arranged in compiler after copied
OutPut:
Enter the size of first array: 3
Enter the elements in first array in ascending order: 2
4
6
Enter the size of second array: 2
Enter the elements in second array: 1
3
The simple merge sorted array is: 1 2 3 4 6