题意为判断一个数是否能被11整除,这里用割减法,存为数组,再从高位开始,一次减去11,看是否能减完
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 #include<stdio.h> 2 #include<string.h> 3 void zhuanhua(char *s,int *a) 4 { 5 int i=0; 6 while(*s) 7 { 8 a[i]=(*s)-'0'; 9 i++; 10 s++; 11 } 12 }//把字符转化为数值存入数组 13 int main() 14 { 15 int i,len,bb[1010],ans[1010],a; 16 char s[1010]; 17 while(scanf("%s",s),strcmp(s,"0")) 18 { 19 len=strlen(s)-1; 20 zhuanhua(s,bb); 21 for(i=0;i<len;i++) 22 { 23 a=bb[i]*10+bb[i+1]; 24 while(a>=11) 25 a-=11; 26 bb[i+1]=a;//从高位往低位依次割减,减到最后为0者就是能被11整除的 27 } 28 if(a!=0) 29 printf("%s is not a multiple of 11.\n",s); 30 else 31 printf("%s is a multiple of 11.\n",s); 32 33 } 34 return 0; 35 }