Program to Count Number of Bits Set.
#include<stdio.h>
int main(){
unsigned int n;
int c=0;
scanf("%d",&n);
while(n!=0) {
if(n&1)
c++;
n>>=1;
}
printf("Number of bits set is %d",c);
return 0;
}
OUTPUTint main(){
unsigned int n;
int c=0;
scanf("%d",&n);
while(n!=0) {
if(n&1)
c++;
n>>=1;
}
printf("Number of bits set is %d",c);
return 0;
}
5
Number of bits set is 2
Number of bits set is 2