Created
December 6, 2012 20:54
-
-
Save juanfal/4228247 to your computer and use it in GitHub Desktop.
Base change, recursive and with a default value to 10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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