+ 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