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

Answers were Sorted based on User's Feedback



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

Answer / minisha

int count(unsigned int n)
{
int c=0;
while(n)
{
n=n&(n-1);
c++
}
return c;
}

Is This Answer Correct ?    0 Yes 0 No

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

Answer / arijit

#include<stdio.h>
#include<conio.h>
void main()
{
int n,cnt,rem
scanf("%d",&n);
cnt=0;
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 0 No

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

Answer / ram

#include<stdio.h>
void main()
{
int a,count=0;
printf("enter a");
scanf("%d",&a);
while(a>0)
{
if(a%2==1)
count++;
a=a>>1;
}
printf("no of on bits =%d ",count);
}

Is This Answer Correct ?    0 Yes 0 No

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

Answer / 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

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

Answer / 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

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

Answer / sriharsha

main()
{
int n;
printf("\n Enter The Number Whose bits have to find");
scanf("%d",&n);
i=i*8;
printf("\n The number of bits in the given number is %d",i);
}

Is This Answer Correct ?    2 Yes 8 No

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

Answer / jaskarann

int i,a;
{
cout<<enter the no whose bits you want to find";
cin>>i;
a=i*8;
cout<<No. of bits in this number is<<a;
getch();

Is This Answer Correct ?    5 Yes 36 No

Post New Answer

More C Interview Questions

What is a pointer variable in c language?

0 Answers  


Write a program to find the smallest and largest element in a given array in c language

11 Answers   Microsoft, Vembu,


A function 'q' that accepts a pointer to a character as argument and returns a pointer to an array of integer can be declared as: A)int (*q(char*)) [] B)int *q(char*) [] C)int(*q)(char*) [] D)None of the Above

2 Answers   Accenture,


What is the use of bitwise operator?

0 Answers  


In C, What is the #line used for?

2 Answers  






write a program that finds the factorial of a number using recursion?

13 Answers   Infosys, TATA,


What is the purpose of 'register' keyword in c language?

0 Answers  


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

0 Answers  


Why isnt there a numbered, multi-level break statement to break out

0 Answers  


what is the output of following question? void main() { int i=0,a[3]; a[i]=i++; printf("%d",a[i] }

3 Answers  


There is a 100-story building and you are given two eggs. The eggs (and the building) have an interesting property that if you throw the egg from a floor number less than X, it will not break. And it will always brake if the floor number is equal or greater than X. Assuming that you can reuse the eggs which didn't broke; you got to find X in a minimal number of throws. Give an algorithm to find X in minimal number of throws.

5 Answers   Yahoo,


What is the best style for code layout in c?

0 Answers  


Categories