Find the how many bits is turned on in a numebr
#include <stdio.h>
int countSetBits(int num);
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
int result = countSetBits(num);
printf("The number of bits turned on in %d is %d.\n", num, result);
return 0;
}
int countSetBits(int num) {
int count = 0;
while (num > 0) {
count += num & 1;
num >>= 1;
}
return count;
}