5
How can I turn this function into a recursive function? I managed to make it iterative in this way:
#include <iostream>
using namespace std;
int main (){
    int n,pot,bin;
    cout << endl << "  Digite o Numero: ";
    cin >> n;
    pot = 1;
    bin = 0;
    while (n > 0){
        bin += (n % 2)* pot;
        pot *= 10;
        n = n/2;
    }
    cout << "  " << "Result: " << bin;
    cin.get();
    return 0;
}
I know this is a question outside the scope, but because you declared the function above the
main()and just wrote it below ? has increased performance or readability of code ? or and just matter of taste ?– Gabriel Rodrigues
It’s been a long time since I programmed in c++. The code gave error when compiling. I chose to declare the function instead of passing it over main, for no particular reason, was what occurred to me at the time.
– ramaral