#include <stdio.h> int countSetBits(unsigned int n) { // Write your code here int len_n = sizeof(n) * 8; int output = 0; while(len_n > 0){ if(n & 1 == 1){ output++; } n >>= 1; len_n--; } return output; } int main() { int n; scanf("%d", &n); printf("%d", countSetBits(n)); return 0; }
Test Cases
Test Results
Input
5
Expected Output
2