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 is define c?
What the advantages of using Unions?
Is there a way to have non-constant case labels (i.e. Ranges or arbitrary expressions)?
How can I manipulate strings of multibyte characters?
Why is event driven programming or procedural programming, better within specific scenario?
How do you determine the length of a string value that was stored in a variable?
which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above
please give me a VIRTUSA sample palcement papers.... you will only send TECHNICAL SECTION..... that is help for me Advance Thanks........................
Are pointers integers in c?
Is c procedural or object oriented?
What does *p++ do? What does it point to?
How can a string be converted to a number?
What are the application of c?
What is the use of define in c?
What is && in c programming?