-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge_two_unsorted_array.cpp
More file actions
64 lines (52 loc) · 1.02 KB
/
merge_two_unsorted_array.cpp
File metadata and controls
64 lines (52 loc) · 1.02 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n1,n2, m;
int a1[10], a2[10], a[20];
cout<<"enter the size of first array: "<<endl;
cin>>n1;
cout<<"enter the size of second array: "<<endl;
cin>>n2;
cout<<"insert the elements of first array: "<<endl;
for(int i = 0; i<n1; i++)
{
cin>>a1[i];
}
cout<<"first array are: " ;
for(int i = 0; i<n1; i++)
{
cout<< a1[i]<< " ";
}
cout<<endl;
cout<<"enter the second arrays elements: " ;
for(int i = 0; i<n2; i++)
{
cin>>a2[i];
}
cout<<"second array are: " ;
for(int i = 0; i<n2; i++)
{
cout<<a2[i]<<" " ;
}
cout<<endl;
m = n1 + n2 ;
int index = 0;
for(int i = 0; i<n1 ;i++)
{
a[index] = a1[i];
index ++;
}
for(int i = 0; i<n2; i++)
{
a[index] = a2[i];
index ++;
}
cout<<"final array are: ";
for(int i = 0; i<m; i++)
{
cout<<a[i]<< " ";
}
cout<<endl;
return 0;
}