Code:
#include stdio.h
int main()
{
unsigned int number;
int count = 0;
printf("Enter the unsigned integer:\n");
scanf("%d", &number);
while (number != 0)
{
if ((number & 1) == 1)
count++;
number = number >> 1;
}
printf("number of one's are :\n%d\n", count);
return 0;
}
Output:
Enter the unsigned integer:
128
number of one's are :
1
$ a.out
Enter the unsigned integer:
-127
number of one's are :
26
More C Programs: