Untitled
unknown
c_cpp
2 years ago
350 B
7
Indexable
#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;
}
Editor is loading...
Leave a Comment