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

Answer Posted / anu

#include<stdio.h>
#include<conio.h>
void main()
{
int n,cnt,rem
scanf("%d",&n);
cnt=1;
while(n!=0)
{
rem=n%2;
n=n/2;
cnt++;
}
printf("number of bits of the number is = %d",cnt);
getch();
}

Is This Answer Correct ?    0 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does a function declared as pascal do differently?

612


How many bytes is a struct in c?

731


What is the heap?

691


How do you do dynamic memory allocation in C applications?

634


What is strcmp in c?

605






What is the right type to use for boolean values in c? Is there a standard type? Should I use #defines or enums for the true and false values?

610


Describe how arrays can be passed to a user defined function

788


What is the Purpose of 'extern' keyword in a function declaration?

656


What are control structures? What are the different types?

605


What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?

596


Is it cc or c in a letter?

574


What is character set?

687


How can I split up a string into whitespace-separated fields?

573


What is switch in c?

652


Is array a primitive data type in c?

584