UVA 10931 Parity Soution

Solve in C++:

#include<bits/stdc++.h>
using namespace std;
main()
{
    int n,i,c=0;
  string a;
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)
            break;
        for(i=0; n>0; i++)
        {
            a[i]=n%2;
            n=n/2;
        }
        printf("The parity of ");
        for(i=i-1; i>=0; i--)
        {

            if(a[i]==1)
                c++;
            printf("%d",a[i]);
        }
        printf(" is %d (mod 2).\n",c);
        c=0;

    }

    return 0;
}

No comments

Most View Post

Recent post

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.