ProAnswers.org

Write a C program to perform merging the elements in an Array ?

#include



#include



void main()



{



int j,h=0,k=0;



int x[4]={1,2,3,4};



int y[4]={5,6,7,8};



int z[8];



clrscr();



printf(“array x:

”);

for(j=0;j<4;j++)



printf(“%d”,x[j]);



printf(“array y:

”);

for(j=0;j<4;j++)



printf(“%d”,y[j]);



j=0;



while(j<8)



{



if(j%2==0)



z[j]=x[k++];



else



z[j]=y[h++];



j++;



}



printf(“array z:

”);

for(j=0;j<8;j++)



printf(“%d”,z[j]);



getch();



}



[b]Output: [/b]



array x:



1 2 3 4



array y:



5 6 7 8



array z:



1 2 3 4 5 6 7 8