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
Why do we use null pointer?
What is mean by data types in c?
What is #include conio h?
What is the explanation for cyclic nature of data types in c?
Can we declare function inside main?
Can a pointer be static?
how to write a c program to print list of fruits in alpabetical order?
what do you mean by inline function in C?
How do you determine the length of a string value that was stored in a variable?
What are the different types of objects used in c?
Can a pointer be volatile in c?
how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software
What is const keyword in c?
Is it fine to write void main () or main () in c?
How can I convert a number to a string?