Untitled

mail@pastecode.io avatar
unknown
c_cpp
8 months ago
350 B
1
Indexable
Never
#include <iostream>
#include <string>


void foo(int n,std::string &bits) {
    
    do {
        bits.push_back(n % 2 + '0');
        n = int(n / 2);
    } while (n != 0);
    reverse(bits.begin(), bits.end());
}

int main()
{
    int n;
    std::string bits;
    std::cin >> n;

    foo(n, bits);

    std::cout << bits;
}

Leave a Comment