โ Back to Arrays
Question 122
Merge Two Arrays
Merge Two Arrays
Two arrays have already been created for you:
- arr1 with values {10, 20, 30} (3 elements)
- arr2 with values {40, 50, 60} (3 elements)
A third array called merged has been declared with size 6.
Your task is to copy all elements from arr1 into the first half of merged, then copy all elements from arr2 into the second half. After that, print all elements of merged on one line separated by spaces.
The key insight is that when copying arr2, the destination index in merged needs to be offset by the size of arr1. So arr2[0] goes to merged[3], arr2[1] goes to merged[4], etc.
Expected output:
10 20 30 40 50 60 Expected Output:
10 20 30 40 50 60
Topics:
Arrays
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.