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
Explain what is #line used for?
Program to find the sum of digits of a given number until the sum becomes a single digit. (e.g. 12345=>1+2+3+4+5=15=>1+5=6)
What is the use of a semicolon (;) at the end of every program statement?
explain how do you use macro?
Explain what are global variables and explain how do you declare them?
Is this program statement valid? INT = 10.50;
Tell me the use of bit field in c language?
Which header file is essential for using strcmp function?
Can an array be an Ivalue?
What is an auto keyword in c?
Is return a keyword in c?
What will be the outcome of the following conditional statement if the value of variable s is 10?
What does %2f mean in c?
Why pointers are used in c?
What are operators in c?