The task only requires us to change a decimal number into binary, count the number of 1s and output the result in a way. So, what do we need to do for converting decimal to binary? We need to keep a sequence, and every time add an element n%2 and divide n to 2 until n reaches 0. This can be done easily with vectors,, just push_back n%2 every time and divide n/2. The rest is easy. Also check out the source code.
No comments:
Post a Comment