Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 9 years ago

# Write a c programme to merge two arrays?

Without using function. Only use array, for loop, while loop and basic operators.

Update:

Suppose first array is of 5 elements and second array is of 6 elements, then third array should be of 5+6=11 elements which shows all the elements of first and second array.

Relevance
• 9 years ago

It depends on what you mean by "merge". You can define an array that's the size of the sum of the two sizes and operate 2 loops to set the values!

If you use a function then it would be easy. Otherwise, if the program doesn't know the sizes of the arrays until runtime you'd need to use dynamic arrays.

I don't really quite understand. Is it simply:

int array1[5];

int array2[6];

// assume values have been assigned

then

int array3[11];

int k;

for( k=0;k<5;k++ ) array3[k] = array1[k];

for( k=0;k<6;k++ ) array3[5+k] = array2[k];

• arai
Lv 4
4 years ago

hi, i beg you to apply the STL library it somewhat is in the C++ regular on the grounds that some years now and stop reinventing the wheel. case in point have a seem to auto_pointer and various style of collections like vector, checklist etc, the quick_sort is already carried out and optimised in that library. in the factors hereunder you will discover 2 function which could make it easier to to. First you merge the two vectors (arrays), and it supply a vector with a threat doubles and the unique_copy function will in basic terms get rid of the double to have your effect. have exciting