为了账号安全,请及时绑定邮箱和手机立即绑定

排除一样的元素在c语言中

标签:
C

int main(){
int a[11];
int b[11];
int i;
int j;
printf("input the a[]:\n");
for(i=0;i<11;i++){
scanf("%d",&a[i]);
printf("");
}

printf("input the b[]:\n");
for(i=0;i<11;i++){
scanf("%d",&b[i]);
printf("");
}
int common=1000;

for(i=0;i<11;i++){
    for(j=0;j<11;j++){
        if(a[i]==b[j]){

            a[i]=common;
        }
        if(a[j]==b[i]){
            b[i]=common;
        }
    }
}
int record=0;
    //sum the zero number
        //remove the unnecessary zero
for(j=0;j<11;j++){
    if(a[j]!=common){
        record++;
    }

}
int share[record];
int test=0;
for(j=0;j<11;j++){
    if(a[j]!=common){
     share[test]=a[j];
     test++;
    }

}
//prevent the same number exist in the share
int recordsec=0;//record the repeat number
for(i=0;i<record-1;i++){
    for(j=i+1;j<record;j++){
        if(share[i]==share[j]){
            share[j]=common;
            recordsec++;
        }
    }
}
//extract the final result array "final"
int finum=record-recordsec;
int final[finum];
int addrec=0;
for(i=0;i<finum;i++){
    if(share[i]!=common){
        final[addrec]=share[i];
        addrec++;
    }
}
for(i=0;i<finum;i++){
    printf("%d",final[i]);
    printf(" ");
}
return 0;

}

点击查看更多内容
2人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消