/**********************************************
The function printbin(int n) prints out the
binary representation of n, assuming n >= 0.
Notice that the base case is not explicit
here!
**********************************************/
#include <iostream>
using namespace std;
void printbin(int n);
int main()
{
// Get integer n, n >= 0
int n;
cout << "Enter non-negative integer: ";
cin >> n;
// Print the binary representation of n
cout << "In binary that's ";
printbin(n);
cout << endl;
return 0;
}
void printbin(int n)
{
// Print everything but the last bit!
if (n > 1)
printbin(n/2);
// Print out the last bit
cout << n%2;
}