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

which one low Priority in c? a)=,b)++,c)==,d)+

10 Answers  


Find the highest of three numbers and print them using ascending orders?

1 Answers  


what is the difference between : func (int list[], ...) or func (int *list , ....) - what is the difference if list is an array and if also if list is a pointer

2 Answers  


What is dynamic memory allocation?

0 Answers  


When should I declare a function?

0 Answers  






Does c have circular shift operators?

0 Answers  


How many data structures are there in c?

0 Answers  


What is the difference between scanf and fscanf?

0 Answers  


# define x=1+4; main() { int x; printf("%d%d",x/2,x/4); }

5 Answers  


11. Look at the Code: #include<string.h> void main() { char s1[]="abcd"; char s2[10]; char s3[]="efgh"; int i; clrscr(); i=strcmp(strcat(s3,ctrcpy(s2,s1))strcat(s3,"abcd")); printf("%d",i); } What will be the output? A)No output B) A Non Integer C)0 D) Garbage

7 Answers   Accenture,


Can a local variable be volatile in c?

0 Answers  


every function has return the value?

1 Answers  


Categories