pad.mattdiesel.co.uk

Snippet - Recursive tobase

Recursive tobase (C++)


Created 2016-03-29 16:39:07.953990 by Matt.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <ostream>
#include <iostream>


void tobase(int N, int b, std::ostream& os) {
    if (N == 0) return;

    tobase(N/b, b, os);
    os << (N%b);
}



int main(int argc, char const *argv[])
{
    tobase(37, 14, std::cout);
    std::cout << std::endl;
    return 0;
}