+ 1
Mada, the clue is in the name of the challenge ânumber of 1âsâ
Your not being asked to count zeros, 79 is 1001111 - which has 5 ones.
Also 99 is 1100011, which has 4 ones.
+ 1
int number {};
std::cin >> number;
int ones {0};
while(true)
{
if(number & 1) ones++;
number >>= 1;
if(number <= 0) break;
}
std::cout << ones;
0
Donât just post a solution, Mada will learn more from fixing their own attempt.
Instead of:
if(number % 2 == 0)
Try !=
Then remove the section at the bottom:
zeroes = zeroes + (totalLength - length);
0
Itâs not stupid, itâs all part of the fun đ
0
DavX
"Donât just post a solution, Mada will learn more from fixing their own attempt."
writes someone who frequently posts full solutions.
Interesting.
https://www.sololearn.com/Discuss/3186848/?ref=app