Untitled
Anonymous
c_cpp
02/11/2024 9:14 AM
468 B
21
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