ACM Q10929: You Can Say 11
Join the DZone community and get the full member experience.
Join For Free// description of your code here
// insert code here..
#include
#include
#define MAX 1000
int main()
{
char num [ MAX ] ;
char c ;
int j = 0 ;
int even=0 , odd=0 ;
while( 1 ){
while( ( num[ j ] = getchar( ) ) && num[ j ] != '\n'){
if( j % 2 == 0){
odd += num[ j ] - '0';
}
else{
even += num[ j ] - '0';
}
j++;
}
num[ j ] = '\0';
if(num[ 0 ] == '0' && j==1){
return 0;
}
j = 0;
if((even-odd)%11==0){
printf("%s is a multiple of 11.\n",num);
}
else{
printf("%s is not a multiple of 11.\n",num);
}
odd = 0 , even =0 ;
}
}
Opinions expressed by DZone contributors are their own.
Comments