-
Notifications
You must be signed in to change notification settings - Fork 85
/
MergeArrayYash.c
56 lines (55 loc) · 1.04 KB
/
MergeArrayYash.c
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
#include <stdio.h>
int main()
{
int a[100], b[100], c[200], i, j, k, n, m;
printf("Enter the size of first array: ");
scanf("%d", &n);
printf("Enter the size of second array: ");
scanf("%d", &m);
printf("Enter the elements of first array: ");
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
printf("Enter the elements of second array: ");
for (i = 0; i < m; i++)
{
scanf("%d", &b[i]);
}
i = 0;
j = 0;
k = 0;
while (i < n && j < m)
{
if (a[i] < b[j])
{
c[k] = a[i];
i++;
k++;
}
else
{
c[k] = b[j];
j++;
k++;
}
}
while (i < n)
{
c[k] = a[i];
i++;
k++;
}
while (j < m)
{
c[k] = b[j];
j++;
k++;
}
printf("The merged array is: ");
for (i = 0; i < n + m; i++)
{
printf("%d ", c[i]);
}
return 0;
}