// CS319 (Scientific Computing) Week03
// 10BinaryAgain.cpp 
// A simple example of a recursive algorithm: 
//    converting from decimal to binary
// Based on Shapira "Solving PDEs in C++", Section 1.18

#include <iostream>
#include <math.h>

int Binary(int a);  // return the binary representation of a

int main(void)
{
  int a, b;

  std::cout << "Input a (decimal) integer a: ";
  std::cin >> a;
  std::cout <<  "You entered: a=" << a << std::endl;

  b = Binary(a);

  std::cout << a << " in binary is  "<< b << std::endl;
  return(0);
}
 
int Binary(int a)
{
  if (a<=1)
    return(a);
  else
    return(10*Binary(a/2) + a%2);
}
