c program to implement merging of arrays

Explanation of the program



This merges two arrays and prints the resultant array after merging. The elements of first array and second array is read into a[ ] and b[ ] respectively. The elements of the array a[ ] is copied into array    c[ ] in the positions c[0] to c[9] and the elements of array b[ ] is copied into array c[ ] in the positions c[10] to c[19]. Now c[ ] contains the resultant array after merging.

Program


#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int a[10],b[10],c[20],j;

printf("Enter the elements of first array");

for(int i=0;i<10;i++)

{

scanf("%d",&a[i]);

}

printf("Enter the elements of second array");

for(i=0;i<10;i++)

{

scanf("%d",&b[i]);

}

for(i=0;i<10;i++)

{

c[i]=a[i];

}

i=0;

for(j=10;j<20;j++)

{

c[j]=b[i];

i++;

}

printf("Array after merging");

for(i=0;i<20;i++)

{

printf("\n%d",c[i]);

}

getch();

}


Output



merging of arrays in c
C program to merge two arrays


No comments: