/*************************************************************
  File: printbin.cpp
  Name: CDR B. A. Osborn
  Description: Read in an integer and write the binary 
               representation using a recursive function
 ************************************************************/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
 
void printbin(int);
 
int main()
{
        int n;
 
        cout << "Enter a non-negative integer: ";
        cin >> n;
 
        cout << "In binary that is ";
        printbin(n);
        cout << endl;
 
        return 0;
}
 
void printbin(int n)
{
        if (n > 1)
        {
               printbin(n/2);
               cout << n%2;
        }
        else
               cout << n;
}

syntax highlighted by Code2HTML, v. 0.9.1