若一个整数的奇位数字之和与偶位数字之和的差能被11整除,则这个数能被11整除。
#include <stdio.h>
#include <string.h>
#define N 1005
inline int ABS(int x)
{
return x > 0 ? x : -x;
}
int main()
{
char data[N];
while(gets(data), strcmp(data, "0"))
{
int l = strlen(data), sum1, sum2;
sum1 = sum2 = 0;
for(int i = 0; i < l; i++)
{
if(i & 1) sum1 += data[i] - '0';
else sum2 += data[i] - '0';
}
if(ABS(sum1 - sum2) % 11 == 0) printf("%s is a multiple of 11.\n", data);
else printf("%s is not a multiple of 11.\n", data);
}
return 0;
}