sundeepblue
4/21/2014 - 2:51 AM

convert integer to another base

convert integer to another base

void convert_base(int n, int b) {
    stack<int> stk;
    while(n != 0) {
        stk.push(n % b);
        n /= b;
    }
    while(!stk.empty()) {
        cout << stk.top();
        stk.pop();
    }
}