Advertisement
raihan02

UVA parity 10931

Jul 4th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main()
  4. {
  5. long long int a,c;
  6. int i=0,count=0 , p;
  7. char s[10 ^ 10000];
  8.  
  9.  
  10. while(scanf("%lld",&a) == 1)
  11. {
  12. if(a == 0)
  13. break;
  14. printf("The parity of ");
  15. c = a;
  16. i = 0;
  17. count = 0;
  18.  
  19. while(a != 0)
  20. {
  21. s[i] = a % 2;
  22.  
  23. a =a / 2;
  24.  
  25. count++;
  26.  
  27. i++;
  28. }
  29. p = 0;
  30. for(i = count - 1; i>= 0; i--)
  31. {
  32. printf("%d",s[i]);
  33. if(s[i] == 1)
  34. p++;
  35. }
  36.  
  37. printf(" is %d (mod 2).\n",p);
  38.  
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement