Given are two one-dimensional arrays A and B which are sorted in ascending
order. Write a program to merge them into a single sorted array C that
contains every item from arrays A and B in ascending order.
# include
# include
void main()
{
int A[20],B[20],C[40],n,i,j=0,t,k=1;
clrscr();
printf("Enter the number of elements in an array:");
scanf("%d",&n);
for(i=0;i {
printf("\nEnter the %d valueof array1:",i+1);
scanf("%d",&A[i]);
}
for(i=0;i {
printf("\nEnter the %d value of array2:",i+1);
scanf("%d",&B[i]);
}
for(i=0;i C[i]=A[i];
for(j=0;j {
C[i]=B[j];
i++;
}
for(j=0;j {
for(k=j;k {
if(C[j]>C[k])
{
t=C[j];
C[j]=C[k];
C[k]=t;
}
}
// k++;
}
for(j=0;j printf("\n%d",C[j]);
getch();
}
/* Output
Enter the number of elements in an array:2
Enter the 1 valueof array1:6
Enter the 2 valueof array1:5
Enter the 1 value of array2:89
Enter the 2 value of array2:1
1
5
6
89
*/
order. Write a program to merge them into a single sorted array C that
contains every item from arrays A and B in ascending order.
# include
# include
void main()
{
int A[20],B[20],C[40],n,i,j=0,t,k=1;
clrscr();
printf("Enter the number of elements in an array:");
scanf("%d",&n);
for(i=0;i
printf("\nEnter the %d valueof array1:",i+1);
scanf("%d",&A[i]);
}
for(i=0;i
printf("\nEnter the %d value of array2:",i+1);
scanf("%d",&B[i]);
}
for(i=0;i
for(j=0;j
C[i]=B[j];
i++;
}
for(j=0;j {
for(k=j;k {
if(C[j]>C[k])
{
t=C[j];
C[j]=C[k];
C[k]=t;
}
}
// k++;
}
for(j=0;j printf("\n%d",C[j]);
getch();
}
/* Output
Enter the number of elements in an array:2
Enter the 1 valueof array1:6
Enter the 2 valueof array1:5
Enter the 1 value of array2:89
Enter the 2 value of array2:1
1
5
6
89
*/