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
What is a substring in c?
Can two or more operators such as and be combined in a single line of program code?
What is hungarian notation? Is it worthwhile?
Why is structure important for a child?
The number of bytes of storage occupied by short, int and long are a) 2, 2 and 4 b) 2, 4 and 4 c) 4, 4 and 4 d) none
What is main () in c?
What is the difference between union and anonymous union?
writ a program to compare using strcmp VIVA and viva with its output.
Tell me is null always defined as 0(zero)?
What is the value of a[3] if integer a[] = {5,4,3,2,1}?
Why is #define used?
int i=10; printf("%d %d %d", i, i=20, i);
Explain the process of converting a Tree into a Binary Tree.
What is bss in c?
Do string constants represent numerical values?