+ 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.
27th Jan 2023, 8:09 PM
DavX
DavX - avatar
+ 1
int number {}; std::cin >> number; int ones {0}; while(true) { if(number & 1) ones++; number >>= 1; if(number <= 0) break; } std::cout << ones;
27th Jan 2023, 8:12 PM
SoloProg
SoloProg - avatar
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);
27th Jan 2023, 8:13 PM
DavX
DavX - avatar
0
It’s not stupid, it’s all part of the fun 👍
27th Jan 2023, 8:26 PM
DavX
DavX - avatar
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
27th Jan 2023, 11:17 PM
Scott D
Scott D - avatar