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

Answer Posted / kavitha

int setbit=1; //Lets start checking from first bit
int numBitSet=0; //Number of bits set in the number

while(setbit>0)
{

if(number&setbit) //bit wise and
numBitSet++;

setbit=setbit<<1;
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are control structures? What are the different types?

822


How a string is stored in c?

792


Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?

2338


What is the use of getchar() function?

839


Write a program to maintain student’s record. Record should not be available to any unauthorized user. There are three (3) categories of users. Each user has its own type. It depends upon user’s type that which kind of operations user can perform. Their types and options are mentioned below: 1. Admin (Search Record [by Reg. No or Name], View All Records, Insert New Record, Modify Existing Record) 2. Super Admin (Search Record [by Reg. No or Name], View All Records, Insert New Record, Modify Existing Record, Delete Single Record) 3. Guest (Search Record [by Reg. No or Name], View All Records) When first time program runs, it asks to create accounts. Each user type has only 1 account (which means that there can be maximum 3 accounts). In account creation, following options are required: Login Name: <6-10 alphabets long, should be unique> Password: <6-10 alphabets long, should not display characters when user type> Confirm Password: Account Type: Login Name, Password and Account Type should be stored in a separate file in encrypted form. (Encryption means that actual information should be changed and Decryption means that Encrypted information is changed back to the actual information) If any of the above mentioned requirement(s) does not meet then point out mistake and ask user to specify information again. When Program is launched with already created accounts, it will ask for user name and password to authenticate. On successful authentication, give options according to the user’s type.

1736


in programming languages a statement or part of a statement that specifies several different execution sequences a) constructs b) distructs c) executes d) none

818


How do you construct an increment statement or decrement statement in C?

982


Write a program to check whether a number is prime or not using c?

794


What is extern storage class in c?

702


What are the two types of functions in c?

754


Tell us the use of fflush() function in c language?

874


Write a code of a general series where the next element is the sum of last k terms.

794


What are run-time errors?

803


Define C in your own Language.

817


How can I sort a linked list?

798