#include <stdio.h>
#include <stdlib.h>
int digit(int x){
int count=1;
while(x>9){
x=x/10;
count++;
}
return count;
}
void Compare(int a,int b,int c,int d){
int x[c],y[d];
int i,j;
int key = 0;
//把每一位数赋值到数组的每一个数 如123 给到 a[0]=3 a[1]=2 a[2]=1
for(i=0;i<c;i++){
x[i]=a%10;
a=a/10;
}
for(j=0;j<d;j++){
y[j]=b%10;
b=b/10;
}
/* 验证一下赋值是否成功
for(i=c-1;i>=0;i--){
printf("%d ",x[i]);
}
printf("\n");
for(j=d-1;j>=0;j--){
printf("%d ",y[j]);
}
*/
for(i=c-1;i>=0;i--){
for(j=d-1;j>=0;j--){
if(x[i]==y[j]){
key=1;
printf("有重复的数字他是:%d\n",x[i]);
}
}
}
if(key==1){
printf("\n");
}else{
printf("没有重复的数字");
}
}
int main()
{
int a,b,c,d;
scanf("%d",&a);
scanf("%d",&b);
//判断出有几位
c=digit(a); //数字a有几位
d=digit(b);
Compare(a,b,c,d); //数字b有几位
return 0;
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交