| 3 | // function for merging two arrays into third array |
| 4 | |
| 5 | void merging(int arr1[], int arr2[], int arr3[]) |
| 6 | { |
| 7 | int i = 0, j = 0, k = 0; |
| 8 | for (i = 0; i < 5 && j < 5;) |
| 9 | { // comparing first array elements with second |
| 10 | if (arr1[i] < arr2[j]) |
| 11 | { |
| 12 | arr3[k] = arr1[i]; |
| 13 | k++; |
| 14 | i++; |
| 15 | } |
| 16 | else |
| 17 | { |
| 18 | arr3[k] = arr2[j]; |
| 19 | k++; |
| 20 | j++; |
| 21 | } |
| 22 | } |
| 23 | while (i < 5) |
| 24 | { // comparing for other elements of first and third arrays |
| 25 | arr3[k] = arr1[i]; |
| 26 | k++; |
| 27 | i++; |
| 28 | } |
| 29 | while (j < 5) |
| 30 | { // comparing for other elements of second and third arrays |
| 31 | arr3[k] = arr2[j]; |
| 32 | k++; |
| 33 | j++; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | int main() |
| 38 | { |