csansoon

P2.05 P28754 Reversed number in binary

Sep 21st, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main () {
  5.     int n;
  6.     cin >> n;
  7.     if (n==0) cout << "0";
  8.     else {
  9.        
  10.         while (n>0) {
  11.             if (n>1) {
  12.                 cout << (n%2);
  13.                 n/=2;
  14.             }
  15.             else {
  16.                 cout << "1";
  17.                 n=0;
  18.             }
Advertisement
Add Comment
Please, Sign In to add comment