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


Please Help Members By Posting Answers For Below Questions

Hai,I have done with my bachelor of commerce and planing to ms,please suggest me how to convince vo for shifting from commerce to computers. Visa on 8 DEC 2014  Npu university

1778


Q.1 write aprogram to stack using linklist o insert 40 items? Q.2 write a program to implement circular queue with help of linklist?

1790


Why is c called a structured programming language?

973


which of the following shows the correct hierarchy of arithmetic operations in C a) (), **, * or/,+ or - b) (),**,*,/,+,- c) (),**,/,*,+,- d) (),/ or *,- or +

1449


What is the difference between functions abs() and fabs()?

849






How to Throw some light on the splay trees?

786


What are the advantage of c language?

740


swap 2 numbers without using third variable?

845


What is pointer to pointer in c?

831


Not all reserved words are written in lowercase. TRUE or FALSE?

960


How can I do graphics in c?

755


How would you rename a function in C?

790


Why should I use standard library functions instead of writing my own?

933


Suppose we have a table name EMP as below. We want to perform a operation in which, I want to change name ‘SMITH’ from as ‘SMITH JAIN’. Also I want to change the name of the column from ENAME to E_NAME. EMPNO ENAME JOB MGR HIREDATE SAL 7369 SMITH Coder 7902 17-DEC-80 800 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 7521 WARD SALESMAN 7698 22-FEB-81 1250

1719


Define Spanning-Tree Protocol (STP)

850