50. WAP to count how many bits are set in a given input number using [goto].
#include <stdio.h>
int
main()
{
int number,bit,set_bit,pos=31;
printf("WAP to count how many bits are
set in a given input number using [goto]\n");
printf("Enter the number : ");
scanf("%d",&number);
L1:
bit=number>>pos&1;
--pos;
set_bit += bit;
if(pos>=0)
goto L1;
printf("Number of set bits in %d is
%d",number,set_bit);
return 0;
}
Comments
Post a Comment