-
Notifications
You must be signed in to change notification settings - Fork 56
/
create cc
65 lines (65 loc) · 1.33 KB
/
create cc
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
58
59
60
61
62
63
64
65
#include<stdio.h>
int removerepeated(int size,int a[]);
void sort(int size,int a[]);
main(){
int i,size1,size2,size,j=0,k;
printf("Enter size of an array1\n");
scanf("%d",&size1);
printf("Enter size of an array2\n");
scanf("%d",&size2);
int a[size1],b[size2],uni[size1+size2];
printf("Enter numbers for array 1\n");
for(i=0;i<size1;i++){
scanf("%d",&a[i]);
}
printf("Enter numbers for array 2\n");
for(i=0;i<size2;i++){
scanf("%d",&b[i]);
}
//union start
for(i=0;i<size1;i++){
uni[j]=a[i];
j++;
}
for(i=0;i<size2;i++){
uni[j]=b[i];
j++;
}
//Sorting
sort(size1+size2,uni);
//Remove repeated elements
size=removerepeated(size1+size2,uni);
printf("Array afetr Union \n");
for(i=0;i<size;i++){
printf("%d\n",uni[i]);
}
//Sorting
}
int removerepeated(int size,int a[]){
int i,j,k;
for(i=0;i<size;i++){
for(j=i+1;j<size;){
if(a[i]==a[j]){
for(k=j;k<size;k++){
a[k]=a[k+1];
}
size--;
}else{
j++;
}
}
}
return(size);
}
void sort(int size,int a[]){
int i,j,temp;
for(i=0;i<size;i++){
for(j=i+1;j<size;j++){
if(a[i]>a[j]){
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}