C/Merging Array !
Expert: Prince M. Premnath - 8/20/2008
Questionhow can i merge the two sorted arrays into a single array? i need to know the codes
AnswerHai Dear bhadz !
We can append the contents of the one array with another array ( merging ) but its not possible to fuse two array's into a single array !
Presenting you a simple code that will merge the contents of the arr2 with arr1
#include<stdio.h>
void main()
{
int arr1[20] = { 10 , 20 , 30 , 40 , 50};
int arr2[] = { 60 , 70 , 80 , 90 , 100};
int i;
/* Given arr1 and arr2 are the two sorted arrays of length 5 , 5 respectivly
Following code will merg the contents of arr2 with the contents of arr1 */
for( i = 0 ; i < 5 ; i++)
arr1[i+5] = arr2[i];
/* Print the contents of the arr1 */
printf("Contents of the arr1 after merging :");
for( i = 0 ; i < 10 ;i++)
printf("%d " , arr1[i]);
}
Note : If you are looking for a different answer , please specify your question clearly , your question will be answered in short !
Thanks and Regards !
Prince M. Premnath