Advertisement
Josif_tepe

Untitled

Feb 24th, 2022
1,054
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <cstring>
  5. using namespace std;
  6. void print_binary(int x) {
  7.     string s = "";
  8.     while(x > 0) {
  9.         s += (x % 2) + '0';
  10.         x /= 2;
  11.     }
  12.     reverse(s.begin(), s.end());
  13.     cout << s << endl;
  14. }
  15. int main() {
  16.     int n;
  17.     cin >> n;
  18.     print_binary(n);
  19.  
  20.     return 0;
  21. }
  22. // 1011000101110
  23. // 1011000101110
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement