Skip to content

Commit c39dd1a

Browse files
authored
Create merge_2_array.c
1 parent 678621a commit c39dd1a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Coding/merge_2_array.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stdio.h>
2+
int main()
3+
{
4+
int arr1size = 5, arr2size = 5, arr_resultsize, i, j;
5+
6+
// elements of first Array
7+
int a[5] = { 1, 2, 3, 4, 5 };
8+
9+
// elements of Second Array
10+
int b[5] = { 6, 7, 8, 9, 10 };
11+
12+
// resultant Array Size Declaration
13+
arr_resultsize = arr1size + arr2size;
14+
int c[arr_resultsize];
15+
16+
// copying array 1 elements into an array
17+
for (i = 0; i < arr1size; i++) {
18+
c[i] = a[i];
19+
}
20+
21+
// copying array 2 elements into an array
22+
for (i = 0, j = arr1size;
23+
j < arr_resultsize && i < arr2size; i++, j++) {
24+
c[j] = b[i];
25+
}
26+
27+
// Array Elements After Merging
28+
for (i = 0; i < arr_resultsize; i++) {
29+
printf("%d ", c[i]);
30+
}
31+
return 0;
32+
}

0 commit comments

Comments
 (0)