1.write a program to merge the arrays
2.write efficient code for extracting unique elements from a
sorted list of array?

Answer Posted / whyname

To merge to arrays ( Note the question has no mention of
sorting the array elements, hence the program below just
merges two arrays)

int array1[5] = {1,2,3,4,5};
int array2[7] = {6,7,8,9,10,11,12};
int i;
int merged[(sizeof(array1)+ sizeof(array2))/sizeof(int)];
memcpy( merged, array1, sizeof(array1));
memcpy( (merged+5), array2, sizeof(array2));

for(i=0;i<(sizeof(merged)/sizeof(int)); i++)
{
printf("%d\n",merged[i]);
}

Is This Answer Correct ?    20 Yes 15 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is #include stdio h?

786


Explain how does free() know explain how much memory to release?

667


to find the closest pair

1931


What is calloc malloc realloc in c?

688


Why c language?

746






Lists the benefits of c programming language?

692


If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?

890


Does sprintf put null character?

690


How can I read data from data files with particular formats?

703


What are the standard predefined macros?

726


What is the difference between union and structure in c?

675


Why c is called a mid level programming language?

695


What is a header file?

726


What is ambagious result in C? explain with an example.

2130


What is use of bit field?

881