Saturday, August 9, 2014

Program to merge two arrays

Program to merge two arrays. This isnt really an important program. But anyways it might be handy.

#include<stdio.h>
main()
{
 int a[50],b[50],i,j,k;
 printf("Enter the number of elements of the first array:\n");
 scanf("%d",&j);
 printf("Enter the elements of the first array:\n");
 for(i=0;i<j;i++)
 scanf("%d",&*(a+i));
 printf("Enter the number of elements of the second array:\n");
 scanf("%d",&k);
 printf("Enter the elements of the second array:\n");
 for(i=0;i<k;i++)
 scanf("%d",&*(b+i));
 for(i=0;i<k;i++)
 *(a+j+i)=*(b+i);
 j=j+k;
 printf("The merged array is :\n");
 for(i=0;i<j;i++)
 printf("%d\t",*(a+i));
}

No comments:

Post a Comment