#include <stdio.h> int countSetBits(unsigned int n) { unsigned int temp=n; int count=0; while(temp) { bool isSet=(temp & 1); if(isSet) { count++; } temp >>=1; } return count; } int main() { int n; scanf("%d", &n); printf("%d", countSetBits(n)); return 0; }
Test Cases
Test Results
Input
5
Expected Output
2