The_Law

Untitled

Oct 3rd, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void)
  5. {
  6.     unsigned int n;
  7.     scanf("%u", &n);
  8.  
  9.     int ans = 0;
  10.  
  11.     for (int i = 0; i < sizeof(n) * 8; ++i)
  12.         ans += (n & (1 << i)) >> i;
  13.  
  14.     printf("%d", ans);
  15.     return 0;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment