count bits c++
#include <iostream>
int countSetBits(int num) {
int count = 0;
while (num) {
count += num & 1;
num >>= 1;
}
return count;
}
int main() {
int num = 10; // Change the value to count set bits in a different number
int result = countSetBits(num);
std::cout << "Number of set bits in " << num << " is: " << result << std::endl;
return 0;
}