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