Computer Science, asked by vamsikrishna9627, 1 year ago

Write a c programme to find the number of 1 in a binary number

Answers

Answered by prabhushankar1771
1

Answer:

For example, binary representation of 4 is 100 and the number of ones in it is 1. Similarly, binary representation of 99 is 1100011 and the number of ones in it is 4.

...

Code:

void countOnes (int n)

{

int count=0;

while (n!=0)

{

n = n & (n-1);

count++;

}

Similar questions