10929 - You can say 11
Introduction to the problem
Your job is, given a positive number N, determine if it is a multiple of eleven.
Description of the 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.
Description of the output
The output of the program shall indicate, for each input number, if it is a multiple of eleven or not.
输入一个数判断是否是11的倍数
Sample input:
112233
30800
2937
323455693
5038297
112234
0
Sample output
112233 is a multiple of 11.
30800 is a multiple of 11.
2937 is a multiple of 11.
323455693 is a multiple of 11.
5038297 is a multiple of 11.
112234 is not a multiple of 11.
解题思路:和http://www.cnblogs.com/EVA00/archive/2013/02/22/2922856.html类似,要注意“011”也是11的倍数
#include<stdio.h> #include<string.h> int main() {char a[1000]; int b[1000],i,flag,n; while(scanf("%s",a)){ if(a[0]=='0'&&a[1]=='\0')break; flag=0; n=strlen(a); for(i=0;i<n;i++) b[i]=a[i]-'0'; for(i=0;i<n;i++){ flag=flag*10+b[i]; flag=flag%11; } if(flag) printf("%s is not a multiple of 11.\n",a); else printf("%s is a multiple of 11.\n",a); } return 0; }