0

Write a c plus plus program that counts the no. of 1 bit in a given integer?

Updated: 9/17/2023

Wiki User

13y ago

int bitcount (unsigned n)

{

int bitc= 0;

while (n) {

++bitc;

n = n&(n-1);

}

return bitc;

}

Wiki User

13y ago

Earn +20 pts
Q: Write a c plus plus program that counts the no. of 1 bit in a given integer?
Submit
Still have questions?
Related questions

Write a C program to extract a given word from a file?

program to extract a given word from a file

Shell program for gcd of three given numbers?

write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? check bellow link http://bashscript.blogspot.com/2009/08/gcd-of-more-than-two-numbers.html

How do you write a program that outputs a given characters in reverse?

write the javascript code to display the reverse no. of given no. (e.g. 247 reverse of 742)

Given the prime factorization of an integer how can you determine if our integer is a perfect square?

Given the prime factorization of an integer how can you determine if our integer is a perfect square?

How do you write a shell script which counts the number of lines and words present in a given file?

#!/bin/sh wc -lw "\$1"

How do you Write a program that determines the number of occurrences of each digit in a given integer n?

there could be a part in it like this: int num, digit; int count [10]; do { digit = num%10; num != 10; ++count[digit]; } while (num);

How do you write a program to find number of zeros for the given number in c program?

Assuming the number is represented by a decimal integer, initialise a counter to zero, then repeatedly divide the number by 10 and until the number is zero. After each division, examine the remainder. Each time the remainder is zero, increment the counter. If the number is represented by a decimal float, repeatedly multiply by 10 until the value is an integer, then perform the previous algorithm.

No.

165

Write a c program to find given number is prime or not?

Yes, do write, or if you're too lazy to your homework, use google.

Need top write a two fractions that are equivalent to the given fraction?

Multiply the numerator (top) and the denominator (bottom) of the given fraction by any non-zero integer. You will have an equivalent fraction.