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
What are formal parameters?
Write a program to swap two numbers without using third variable in c?
What does %c do in c?
What is clrscr in c?
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
How many keywords (reserve words) are in c?
Where can I get an ansi-compatible lint?
What is the purpose of 'register' keyword?
What does c value mean?
Can an array be an Ivalue?
Write a program to swap two numbers without using a temporary variable?
What is queue in c?
How do you determine whether to use a stream function or a low-level function?
regarding pointers concept
Explain data types & how many data types supported by c?