本人在实训中遇一C语言题目——集合的操作问题,,求高手解答!!!!

2024-11-23 01:31:50
推荐回答(1个)
回答1:

程序忙你写好,希望对你有帮助!效果图及代码如下(注:在输入限制上为了方便调试未设为10以上):#include"stdio.h"
main()
{
int i,j,count=0,co_a,co_b,ck=0,a[50],b[50],c[100],stop,in=0;
while(stop!=0)
{
printf("\n >> 1:Input || 2:Get_Result || 0:Esc\n:");
scanf("%d",&stop);
while(stop!=0&&stop!=1&&stop!=2)scanf("%d",&stop);
if(stop==2&&in==0)
{
stop=1;
printf("Data does not exist,please input data!\n");
}
switch(stop)
{
case 1:
printf("Enter number of A and B!!!\nNo_A=");
scanf("%d",&co_a);
printf("No_B=");
scanf("%d",&co_b);
for(i=0;i {
printf("a[%d]=",i+1);
scanf("%d",&a[i]);
}
printf("\n");
for(i=0;i {
printf("b[%d]=",i+1);
scanf("%d",&b[i]);
}
in=1;
break;
case 2:
printf(" (A-B)= ");
for(i=0;i {
for(j=0;j if(a[i]==b[j])ck=1;
if(ck==0)
printf("%d ",c[count++]=a[i]);
ck=0;
}
printf("\n\n (B-A)= ");
for(i=0;i {
for(j=0;j if(b[i]==a[j])ck=1;
if(ck==0)
printf("%d ",c[count++]=b[i]);
ck=0;
}
printf("\n\n (A-B)U(B-A)= ");
for(i=0;i printf("%d ",c[i]);
getch();
break;
}
}
}