viewing paste baseCalulator | C++

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <iostream>
 
const int BASE = 2;
 
void calcBase(int n){
    
    if(n > 0){
        
        if(n/BASE > 0)
            
            calcBase(n/BASE);
        
        std::cout << n % BASE;
    }
    return;
}
 
int main () {
    
    std::cout << "Input: ";
    
    int value = 0;
    
    std::cin >> value;
    
    calcBase(value);
    
    return 0;
}
Viewed 1318 times, submitted by Streusel.