Give a method to count the number of ones in a 32 bit number?
Answer Posted / vignesh1988i
#include<stdio.h>
#include<conio.h>
void main()
{
unsigned i;
int j=0,count=0;;
printf("Enter the number :");
scanf("%ld",&i);
while(j<=31)
{
if(!(((i>>j)&1)^1))
count++;
j++;
}
printf("\nnumber of 1's in ur number is : %d",count);
getch();
}
thank u
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How is a null pointer different from a dangling pointer?
write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.
Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..
What is the difference between variable declaration and variable definition in c?
what do you mean by inline function in C?
What is data types?
how to execute a program using if else condition and the output should enter number and the number is odd only...
What is dynamic variable in c?
Explain about the constants which help in debugging?
Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?
the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none
How does normalization of huge pointer works?
Write a program to know whether the input number is an armstrong number.
What is an auto variable in c?