-
Notifications
You must be signed in to change notification settings - Fork 0
/
Union_Exo5.cpp
60 lines (60 loc) · 926 Bytes
/
Union_Exo5.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
58
59
60
#include<stdlib.h>
#include<stdio.h>
int main()
{
int ia,ib,ic,a,b,c,C[60],A[30],B[30];
do{
printf("saisir la taille de A : ");
scanf("%d",&a);
}while(a<1 || a>30);
for(ia=0;ia<a;ia++)
{
printf("saisir A[%d] :",ia);
scanf("%d",&A[ia]);
}
do{
printf("saisir la taille de B : ");
scanf("%d",&b);
}while(b<1 || b>30);
for(ib=0;ib<b;ib++)
{
printf("saisir B[%d] :",ib);
scanf("%d",&B[ib]);
}
ia=0; ib=0; ic=0;
while(ia<a && ib<b)
{
for(ib=0;ib<b;ib++){
if(A[ia]==B[ib])
{
C[ic]=A[ia];
ia++;
ic++;
}
}
else
{
C[ic]=A[ia];
ic++;
ia++;
C[ic]=B[ib];
ic++;
ia++;
}
}
while(ib<b)
{
C[ic]=B[ib];
ic++;
ib++;
}
while(ia<a)
{
C[ic]=A[ia];
ia++;
ic++;
}
c=ic;
for(ic=0;ic<c;ic++){
printf("C[%d]= %d \n",ic ,C[ic]);
}system("pause");}