write a program to find out number of on bits in a number?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
Explain pointer. What are function pointers in C?
Explain 'bus error'?
1.int a=10; 2.int b=20; 3. //write here 4.b=30; Write code at line 3 so that when the value of b is changed variable a should automatically change with same value as b. 5.
Consider a language that does not have arrays but does have stacks as a data type.and PUSH POP..are all defined .Show how a one dimensional array can be implemented by using two stacks.
When is an interface "good"?
What is clrscr in c?
to find the program of matrix multiplication using arrays
What is difference between Structure and Unions?
What is diffrance between declaration and defination of a variable or function
two variables are added answer is stored on not for third variable how it is possible?
Explain how can a program be made to print the name of a source file where an error occurs?
what will be the result of the following program ? char *gxxx() { static char xxx[1024]; return xxx; } main() { char *g="string"; strcpy(gxxx(),g); g = gxxx(); strcpy(g,"oldstring"); printf("The string is : %s",gxxx()); } a) The string is : string b) The string is :Oldstring c) Run time error/Core dump d) Syntax error during compilation e) None of these