2.题目:编一C程序,它能读入构成集合A,B的两串非零整数x1,x2,……,xm,0,y1,y2,……,yn,0 。计算A与B的交集A∩B,再以由小到大的顺序输出A∩B中的元素,A∩B为空时无输出。 (注:可执行程序命名为e14_2.exe)
程序设计:
main()
{int a[80],b[80],ab[80],x,al,bl,abl,i,j,n,k;
printf("Please enter int numbers:\n");
i=-1;
do {i++;
scanf("%d",&a[i]);
}
while (a[i]!=0);
al=i;printf("%d\n",al);
i=-1;
do {i++;
scanf("%d",&b[i]);
}
while (b[i]!=0);
bl=i;printf("%d\n",bl);
abl=-1;
for (i=0;ifor (j=0;jif (a[i]==b[j])
{abl++;
ab[abl]=a[i];
break;
}
if (abl!=-1)
for (k=1;kfor (j=abl-1,i=0;iif (ab[j]{x=ab[j];ab[j]=ab[j-1];ab[j-1]=x;}
if (abl!=-1)
for (i=0;iprintf("%d ",ab[i]);
printf("\n");
}