Skip to content

Instantly share code, notes, and snippets.

@juanfal
Created December 6, 2012 20:54
Show Gist options
  • Save juanfal/4228247 to your computer and use it in GitHub Desktop.
Save juanfal/4228247 to your computer and use it in GitHub Desktop.
Base change, recursive and with a default value to 10
#include <iostream>
using namespace std;
void binary (int a, int base = 10);
int main()
{
int a, base;
cout << "Enter number and base:";
cin >> a >> base;
binary (a, base);
cout << endl;
return 0;
}
void binary (int a, int base)
{
if (a < base)
cout << a;
else {
binary(a / base, base);
cout << a % base;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment