Guest User

10931 - Parity

a guest
Dec 13th, 2012
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3.  
  4.  
  5. int main()
  6. {
  7.     long long int num,count,i,s,x,l;
  8.     char  str[200000];
  9.     long long int value[200000];
  10.     while(scanf("%lld",&num)==1)
  11.     {
  12.     if(num==0)
  13.         break;
  14.      if(num==1)
  15.            printf("The parity of 1 is 1 (mod 2).\n");
  16.        else{
  17.     count=0;
  18.     i=0;
  19.     while(num!=0)
  20.     {
  21.         if(num%2==1)
  22.         count++;
  23.         s=num/2;
  24.         value[i++]=num%2;
  25.         num=s;
  26.  
  27.     }
  28.     x=0;
  29.     for(l=i-1;l>=0;l--)
  30.          str[x++]=value[l]+'0';
  31.        str[x]='\0';
  32.         printf("The parity of %s is %lld (mod 2).\n",str,count);
  33.        }
  34.     }
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment