← Back to STL Containers
Question 515
Decimal to Binary with a Stack
Decimal to Binary with a Stack
Write a functionstring toBinary(int n)that returns the binary representation ofnas a string, using astack<int>. You may assumenis 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
Sign in to use hintsTopics:
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.