#include <stdio.h> #include <stdint.h> int countSetBits(unsigned int n) { // Write your code here uint8_t ctr = 0; do { ctr += (n & 0x01); n >>= 1; } while (n); return ctr; } int main() { int n; scanf("%d", &n); printf("%d", countSetBits(n)); return 0; }
Test Cases
Test Results
Input
5
Expected Output
2