-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMerging.c
More file actions
56 lines (56 loc) · 680 Bytes
/
Merging.c
File metadata and controls
56 lines (56 loc) · 680 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
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#define size 5;
int main()
{
int A[10],B[10],C[20],m,n,k,i,j;
printf("Enter the size of first array\n");
scanf("%d",&m);
printf("Enter the element\n");
for(i=0;i<m;i++)
{
scanf("%d",&A[i]);
}
printf("Enter the size of second array\n");
scanf("%d",&n);
printf("Enter the element\n");
for(i=0;i<n;i++)
{
scanf("%d",&B[i]);
}
i=0;
j=0;
k=0;
while(i<m && j<n)
{
if(A[i]<=B[j])
{
C[k]=A[i];
k++;
i++;
}
else
{
C[k]=B[j];
k++;
j++;
}
}
while(i<m)
{
C[k]=A[i];
k++;
i++;
}
while(j<n)
{
C[k]=B[j];
k++;
j++;
}
printf("After merging\n");
for(i=0;i<k;i++)
{
printf("%d\t",C[i]);
}
return 0;
}