Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Program: bin.cc
- // Author: Yoan Pinzon
- // Date: Agosto 30, 2006
- #include <iostream>
- using namespace std;
- int main()
- {
- int n; // number to convert to binary
- while (cin >> n)
- {
- if (n > 0)
- {
- cout << n << " (decimal) = ";
- while (n > 0)
- {
- cout << n%2;
- n = n/2;
- }
- cout << " (binary) in reverse order" << endl;
- }
- else
- cout << "Please enter a number." << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement