//* Recursive base conversion *

#include <iostream> using namespace std; void BASE(int num, int base); int main() { int n, b; cout << "Please enter the integer number and the target base "; cin >> n >> b; cout << n << " converted to " << b << " base is "; BASE(n, b); cout << endl; return(0); } void BASE(int num, int base) { // error parameter handling if (base<2||base>10) return; // special case if (num<0) { cout <<"-"; BASE(-num, base); return; } // recursion limit if (num==0) return; // recursive definition int rem=num%base; BASE(num/base, base); // delayed priont results in inverse printout // of resulting computations - good trick! cout << rem; }