Advertisement
idsystems

CPP_Practica60_Binario

Mar 13th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. // Program: bin.cc
  2. // Author:  Yoan Pinzon
  3. // Date:    Agosto 30, 2006
  4.  
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.    int n; // number to convert to binary
  12.  
  13.    while (cin >> n)
  14.    {
  15.       if (n > 0)
  16.       {
  17.          cout << n << " (decimal) = ";
  18.          while (n > 0)
  19.          {
  20.             cout << n%2;
  21.             n = n/2;
  22.          }
  23.          cout << " (binary) in reverse order" << endl;
  24.       }
  25.       else
  26.          cout << "Please enter a number." << endl;
  27.    }
  28.  
  29.    return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement