• Source
    1. #include<stdio.h>
    2. int main()
    3. {
    4. long long int n,i,j,arr[100],mod,count;
    5. while(scanf("%lld",&n)==1)
    6. {
    7. if(n==0)
    8. {
    9. break;
    10. }
    11. i=0;
    12. count=0;
    13. while(n>0)
    14. {
    15. mod=n%2;
    16. arr[i]=mod;
    17. i++;
    18. n=n/2;
    19. }
    20. for(j=i-1;j>=0;j--)
    21. {
    22. if(arr[j]==1)
    23. {
    24. count++;
    25. }
    26. }
    27. printf("The parity of ");
    28. for(j=i-1;j>=0;j--)
    29. {
    30. printf("%lld",arr[j]);
    31. }
    32. printf(" is %lld (mod 2).\n",count);
    33. }
    34. return 0;
    35. }