Array Merging

The way of combining two arrays into a single array is known as Array merging.

In this program, we are going to merge the content of two arrays into a single array.

#include <stdio.h>
int main()
{
 int a[5]={1,3,5,7,9};
 int b[5]={2,4,6,8,10};
 int c[10];
 int i,j;

 for(i=0,j=0;i<10;i+=2,j++)
 {
   c[i] = a[j];
   c[i+1] = b[j];
 }

 printf("Merged Array : \n");
 for(i=0;i<10;i++)
 {
  printf("%d ",c[i]);
 }


 return 0;
}
OUTPUT:
Merged Array :
1 2 3 4 5 6 7 8 9 10

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *