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

Why do we use null pointer?

782


What is mean by data types in c?

752


What is #include conio h?

782


What is the explanation for cyclic nature of data types in c?

869


Can we declare function inside main?

748


Can a pointer be static?

814


how to write a c program to print list of fruits in alpabetical order?

2063


what do you mean by inline function in C?

817


How do you determine the length of a string value that was stored in a variable?

853


What are the different types of objects used in c?

740


Can a pointer be volatile in c?

722


how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software

3035


What is const keyword in c?

936


Is it fine to write void main () or main () in c?

732


How can I convert a number to a string?

819