decimal to binary on c++
<pre><code>#include &lt;iostream&gt;

using namespace std;

int main()
{
   int q, r, x;
    cout &lt;&lt; "enter #: ";
    cin &gt;&gt; x;
    q=x;
        while (q != 1)
        {
            r = (q % 2);
            cout &lt;&lt; r &lt;&lt; endl;
            q = (q/2);
            if (q==1)

            cout &lt;&lt; q;
                break;
            }
    return 0;
        }
</code></pre>

<p>*I dk how to make it so it works with the length of input</p>
