Write a program in C to merge the elements in an array
#include<stdio.h>
#include<conio.h>
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:\n”);
for(j=0;j<4;j++)
printf(“%d”,x[j]);
printf(“array y:\n”);
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:\n”);
for(j=0;j<8;j++)
printf(“%d”,z[j]);
getch();
}
Post a Comment