Skip to content

Commit 2834e2f

Browse files
Dynamic Array Problem-2 Solved
1 parent 4c8154f commit 2834e2f

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

dynamic_array_problem-2.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n, m;
7+
8+
cin >> n;
9+
10+
int *a = new int[n];
11+
12+
for (int i = 0; i < n; i++)
13+
{
14+
cin >> a[i];
15+
}
16+
17+
cin >> m;
18+
19+
int *b = new int[m];
20+
21+
for (int i = 0; i < n; i++)
22+
{
23+
b[i] = a[i];
24+
}
25+
26+
delete[] a;
27+
28+
for (int i = n; i < m; i++)
29+
{
30+
cin >> b[i];
31+
}
32+
cout << endl;
33+
34+
for (int i = 0; i < m; i++)
35+
{
36+
cout << b[i] << " ";
37+
}
38+
39+
return 0;
40+
}

dynamic_array_problem-2.exe

52.4 KB
Binary file not shown.

input.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
5
2-
30 50 10 20 40
2+
1 2 3 4 5
3+
10
4+
6 7 8 9 10

output.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
30 50 10 20 40
1+
2+
1 2 3 4 5 6 7 8 9 10

0 commit comments

Comments
 (0)