CJCoding With Joseph
15free / daySign inCreate account

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, so 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.