-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeArrays.cpp
More file actions
33 lines (23 loc) · 952 Bytes
/
Copy pathMergeArrays.cpp
File metadata and controls
33 lines (23 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
using namespace std;
void mergeArrays(int arr1[], int arr2[], int array1Size, int array2Size){
cout << "First array: " << endl;
for(int i = 0; i < array1Size; i++) cout << arr1[i] << endl;
cout << "Second array: " << endl;
for(int j = 0; j < array2Size; j++) cout << arr1[j] << endl;
int resultSize = array1Size + array2Size;
int resultArray[resultSize];
for(int i = 0; i < array1Size; i++) resultArray[i] = arr1[i];
for(int j = 0; j < array2Size; j++) resultArray[array1Size + j] = arr2[j];
cout << "After merging: " << endl;
for(int k = 0; k < resultSize; k++) cout << resultArray[k] << endl;
}
int main()
{
int numbers1[] = {3,4,5,2,2,4,5,7,9};
int size1 = sizeof(numbers1) / sizeof(numbers1[0]);
int numbers2[] = {2,78,86,5,9,9,21,2};
int size2 = sizeof(numbers2) / sizeof(numbers2[0]);
mergeArrays(numbers1, numbers2, size1,size2);
return 0;
}