Write a c programme to merge two arrays?
Without using function. Only use array, for loop, while loop and basic operators.
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.
- modulo_functionLv 79 years agoFavorite Answer
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:
// assume values have been assigned
for( k=0;k<5;k++ ) array3[k] = array1[k];
for( k=0;k<6;k++ ) array3[5+k] = array2[k];
- araiLv 44 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