-
Notifications
You must be signed in to change notification settings - Fork 0
/
q13.cpp
57 lines (40 loc) · 1.21 KB
/
q13.cpp
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
#include <stdio.h>
void concatenateArrays(int arr1[], int size1, int arr2[], int size2, int result[], int *resultSize) {
int i, j;
for (i = 0; i < size1; i++) {
result[i] = arr1[i];
}
for (j = 0; j < size2; j++) {
result[i + j] = arr2[j];
}
*resultSize = size1 + size2;
}
void printArray(int arr[], int size) {
for (int i = 0; i < size; i++) {
printf("%d ", arr[i]);
}
printf("\n");
}
int main() {
int size1, size2;
printf("Enter the size of the first array: ");
scanf("%d", &size1);
int arr1[size1];
printf("Enter the elements of the first array:\n");
for (int i = 0; i < size1; i++) {
scanf("%d", &arr1[i]);
}
printf("Enter the size of the second array: ");
scanf("%d", &size2);
int arr2[size2];
printf("Enter the elements of the second array:\n");
for (int i = 0; i < size2; i++) {
scanf("%d", &arr2[i]);
}
int resultSize = size1 + size2;
int result[resultSize];
concatenateArrays(arr1, size1, arr2, size2, result, &resultSize);
printf("Concatenated array: ");
printArray(result, resultSize);
return 0;
}