#include <stdio.h> int countSetBits(unsigned int n) { int sum; for(int i=0; i<sizeof(unsigned int)*8; i++){ sum += (n >> i) & 1; } return sum; } int main() { int n; scanf("%d", &n); printf("%d", countSetBits(n)); return 0; }
Test Cases
Test Results
Input
5
Expected Output
2