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

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is the role you expect in software industry?

1660


What is #include called?

575


how to write optimum code to divide a 50 digit number with a 25 digit number??

2757


In cryptography, you could often break the algorithm if you know what was the original (plain) text that was encoded into the current ciphertext. This is called the plain text attack. In this simple problem, we illustrate the plain text attack on a simple substitution cipher encryption, where you know each letter has been substituted with a different letter from the alphabet but you don’t know what that letter is. You are given the cipherText as the input string to the function getwordSets(). You know that a plain text "AMMUNITION" occurs somewhere in this cipher text. Now, you have to find out which sets of characters corresponds to the encrypted form of the "AMMUNITION". You can assume that the encryption follows simple substitution only. [Hint: You could use the pattern in the "AMMUNITION" like MM occurring twice together to identify this]

1963


What are runtime error?

634






What are linked lists in c?

653


Explain union.

641


What does static variable mean in c?

657


Explain what is the difference between the expression '++a' and 'a++'?

631


Which control loop is recommended if you have to execute set of statements for fixed number of times?

817


What is a good way to implement complex numbers in c?

600


Explain two-dimensional array.

633


What is the difference between far and near ?

691


Explain what is wrong with this statement? Myname = ?robin?;

1044


Write a program which returns the first non repetitive character in the string?

610