write a program to find out number of on bits in a number?

Answer Posted / arijit

#include<stdio.h>
#include<conio.h>
void main()
{
int n,cnt,rem
scanf("%d",&n);
cnt=0;
while(n!=0)
{
rem=n%2;
n=n/2;
cnt++;
}
printf("number of bits of the number is = %d",cnt);
getch();
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of macro formats?

613


Write a program to find factorial of a number using recursive function.

652


What does volatile do?

571


List a few unconditional control statement in c.

564


How do I use strcmp?

647






explain what is fifo?

642


Write a C program that will accept a hexadecimal number as input and then display a menu that will permit any of the following operations to be carried out: Display the hexadecimal equivalent of the one's complement. (b) Carry out a masking operation and then display the hexadecimal equivalent of the result. (c) Carry out a bit shifting operation and then display the hexadecimal equivalent of the result. (d) Exit. If the masking operation is selected, prompt the user lor the type of operation (bitwise and, bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit shifting operation is selected. prompt the user for the type of shift (left or right), and then the number of bits. Test the program with several different (hexadecimal) input values of your own choice.

4847


in iso what are the common technological language?

1639


How can I read a binary data file properly?

637


Describe static function with its usage?

617


In which layer of the network datastructure format change is done

1439


Explain the difference between exit() and _exit() function?

639


In C programming, what command or code can be used to determine if a number of odd or even?

627


please give me some tips for the placement in the TCS.

1640


Add Two Numbers Without Using the Addition Operator

357