write a program to find out number of on bits in a number?
Answer Posted / krishna kanth
#include<stdio.h>
main()
{
int setbit=1;
int number=16;//for example
int numBitSet=0;
clrscr();
while(setbit<=number)//important and optimized condition
{
if(number&setbit)
numBitSet++;
setbit=setbit<<1;
}
printf("%d",numBitSet);
getch();
}
| Is This Answer Correct ? | 10 Yes | 3 No |
Post New Answer View All Answers
What are the types of pointers in c?
Tell us the use of fflush() function in c language?
What are structure members?
How to draw the flowchart for structure programs?
Explain what standard functions are available to manipulate strings?
What is the difference between arrays and pointers?
What does the c preprocessor do?
Explain what does it mean when a pointer is used in an if statement?
What do header files do?
if a is an integer variable, a=5/2; will return a value a) 2.5 b) 3 c) 2 d) 0
C program to find all possible outcomes of a dice?
write a programe to accept any two number and check the following condition using goto state ment.if a>b,print a & find whether it is even or odd and then print.and a
using only #include
What does p mean in physics?
In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between 1 and N.Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the C*2 prime numbers from the center of the list if there are an even number of prime numbers or (C*2)-1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.