C Program for MERGING of Two Arrays with out using Third Array

include

int main()

{
int n1, n2, i, j, *p, *q, a[10], b[10];
printf(“Enter the number of elements in array 1 :: “);
scanf(“%d”, &n1);

printf("Enter the elements : ");
for(i = 0; i < n1; i++)
{
    scanf("%d", &a[i]);
}
printf("Enter the number of elements in array 2 :: ");
scanf("%d", &n2);
printf("Enter the elements : ");

for(i = 0; i < n2; i++)
{
    scanf("%d", &b[i]);
}

//MERGING THE ARRAY

p=a;
q=b;
for(i = 0, j = n1; i < n2; i++, j++)
{
    *(p+j) = *(q+i);
}
printf("The merged array is :: ");
for(i = 0; i < j; i++)
    printf("%d  ", a[i]);

printf("\n");
return 0;

}

OUTPUT:
Enter the number of elements in array 1 :: 5
Enter the elements : 1 2 3 4 5
Enter the number of elements in array 2 :: 5
Enter the elements : 6 7 8 9 10
The merged array is :: 1 2 3 4 5 6 7 8 9 10

Leave a Reply

Your email address will not be published.