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

Answer Posted / madhu

#include <stdio.h>

main()
{
int number;
int setbit=1; //Lets start checking from first bit
int numBitSet=0; //Number of bits set in the number
printf("enter the number");
scanf("%d", &number);

while(setbit>0)
{

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

setbit=setbit<<1;
}
printf("%d",numBitSet);
}
full program of the first ans...

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are formal parameters?

664


Write a program to swap two numbers without using third variable in c?

622


What does %c do in c?

591


What is clrscr in c?

682


Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Assume that there are not more than 450 students in the college. 1.write a function to print names of all students who joined in a particular year 2.write a function to print the data of a student whose roll number is given

2526






How many keywords (reserve words) are in c?

626


Where can I get an ansi-compatible lint?

646


What is the purpose of 'register' keyword?

694


What does c value mean?

636


Can an array be an Ivalue?

669


Write a program to swap two numbers without using a temporary variable?

613


What is queue in c?

584


How do you determine whether to use a stream function or a low-level function?

658


regarding pointers concept

1579


Explain data types & how many data types supported by c?

588