Wednesday, 2 July 2014

Merge two arrays

#include<conio.h>
#include<stdio.h>
int main()
{
int arr1[10],arr2[10],arr3[20],n1,n2,i,j=0;
printf("Enter the number of elements in array 1: ");
scanf("%d",&n1);
printf("\nEnter elements in array 1: ");
for(i=0;i<n1;i++)
scanf("%d",&arr1[i]);


printf("\nEnter the number of elements in array 2: ");
scanf("%d",&n2);
printf("\nEnter elements in array 2: ");
for(i=0;i<n2;i++)
scanf("%d",&arr2[i]);

for(i=0;i<n1;i++)
{
arr3[i]=arr1[i];
}
for(i=n1;i<n1+n2;i++)
{
arr3[i]=arr2[j];
j++;
}

printf("\nMerging Complete; the new arrray is : \n");
for(i=0;i<n1+n2;i++)
{
printf("%d",arr3[i]);
}
getch();
return 0;
}



No comments:

Post a Comment