-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointer_Array_exercise.cpp
More file actions
46 lines (38 loc) · 885 Bytes
/
pointer_Array_exercise.cpp
File metadata and controls
46 lines (38 loc) · 885 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
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <string>
using namespace std;
int *apply_all(int *array1, size_t s1, int *array2, size_t s2);
void print_array(int *array, size_t s);
int main(){
int array1[] {1,2,3,4,5};
int array2[] {1,2,3};
int *array3;
array3 = apply_all(array1, 5, array2,3);
print_array(array3, 15);
delete[] array3;
return 0;
}
int *apply_all(int *array1, size_t s1, int *array2, size_t s2)
{
int *new_array {nullptr};
size_t size_array = s1*s2;
new_array = new int[size_array];
int position = 0;
for (int i{0}; i<s2; i++)
{
for (int j{0}; j<s1; j++)
{
new_array[position] = array2[i]*array1[j];
position++;
}
}
return new_array;
}
void print_array(int *array, size_t s)
{
for(int i{0}; i<s; i++)
{
cout << array[i] << " ";
}
cout << endl;
}