Skip to content

Instantly share code, notes, and snippets.

@Yi-Tseng
Created September 24, 2012 15:03
Show Gist options
  • Save Yi-Tseng/3776418 to your computer and use it in GitHub Desktop.
Save Yi-Tseng/3776418 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[])
{
char num[1010] = {0};
while(scanf("%s",num)!=EOF){
if(strcmp(num, "0") == 0){
break;
}
size_t len = strlen(num);
int c;
int odd = 0;
int even = 0;
int res;
for(c=0;c<len;c++){
if(c%2 == 0){
even += num[c]-'0';
}else{
odd +=num[c]-'0';
}
}
if(even > odd){
res = (even-odd)%11;;
}else{
res = (odd-even)%11;;
}
if(res == 0){
printf("%s is a multiple of 11.\n",num);
}else{
printf("%s is not a multiple of 11.\n",num);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment