CJCoding With Joseph
15free / daySign inCreate account

Decimal to Binary with a Stack

Write a function string toBinary(int n) that returns the binary representation of n as a string, using a stack<int>. You may assume n is at least 1. Do not add leading zeros.

Example: toBinary(10) returns "1010" and the test prints it on its own line (see Expected Output).

Do NOT write a main function.

Expected Output:

1010
1
11111111

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
STL ContainersStacks
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.