UVA 10931 - Parity

UVA Sep 1, 2020

Problem PDF

Solution:

#include
int main()
{
    unsigned long int n;
    int i,c,b[1000];
    while(scanf("%lu",&n)==1)
    {
        if(n==0)
        break;
        i=0;
        while(n!=0)
        {
            b[i]=n%2;
            n/=2;
            i++;
        }
        c=0;
        printf("The parity of ");
        for(i=i-1;i>=0;i--)
        {
            printf("%d",b[i]);
            if(b[i]==1)
            c++;
        }
        printf(" is %d (mod 2).\n",c);

    }
    return 0;
}
https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/10931/10931.cpp

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.