Merge 2 arrays in C

Previous
Next

Merge arrays:

  • Read 2 array of elements
  • Adding all elements of one array at the end of second array is called merging
  • We can also call it as concatenation of two arrays.
#include<stdio.h>
int main()
{
	int a[30], b[10], m, n, i;
	
	printf("Enter size of A : ");
	scanf("%d", &m);
	printf("Enter %d elements into A : \n", m);
	for(i=0 ; i<m ; i++)
		scanf("%d", &a[i]);
	
	printf("Enter size of B : ");
	scanf("%d", &n);
	printf("Enter %d elements into B : \n", n);
	for(i=0 ; i<n ; i++)
		scanf("%d", &b[i]);
	
	for(i=0 ; i<n ; i++)
		a[m+i] = b[i];
		
	printf("After Merge Array A is : \n");
	for(i=0 ; i<m+n ; i++)
		printf("%d\n", a[i]);
	return 0;
}
Previous
Next

Add Comment

Courses Enquiry Form