DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

ACM Q10929: You Can Say 11

01.19.2007
| 842 views |
  • submit to reddit
        // description of your code here

// insert code here..
#include <stdio.h>
#include <stdlib.h>
#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 ;
    }
}
    
    Tags:
  • C