Description

Your job is, given a positive number N, determine if it is a **multiple of eleven**.

Input

The input is a file such that each line contains a positive number.

A line containing the number 0 is the end of the input.

**The given numbers can contain up to 1000 digits.**

Output

The output of the program shall indicate, for each input number, if it is a multiple of eleven or not.

#include
#include
#include
int main(void)
{
char s[1005];
int n,i,sum1,sum2;
while(scanf("%s", s) != EOF) // while scanf didn't error
{
if(strcmp(s,"0")==0)break;
sum1=sum2=0;
n=strlen(s);
for(i=0;i < n;i++)
{
if(i&1) //取i和1二進位的and運算，一定只剩下最低位，1就是odd
sum1+=s[i]-'0'; //s[i]-48，atoi只能atoi(char *str)或atoi("123")，不能只放s[i]
else
sum2+=s[i]-'0';
}
n=abs(sum1-sum2); //絕對值輸出
if(n%11==0)
printf("%s is a multiple of 11.n",s);
else
printf("%s is not a multiple of 11.n",s);
}
return 0;
}

### Like this:

Like Loading...

*Related*