Answer:
Check the explanation
Step-by-step explanation:
#include <iostream>
#include <string>
using namespace std;
string decimalToBinaryRecursive(int n) {
if(n == 0) {
return "0";
} else if(n == 1) {
return "1";
} else {
int d = n % 2;
string s;
if (d == 0) {
s = "0";
} else {
s = "1";
}
return decimalToBinaryRecursive(n/2) + s;
}
}
int main() {
cout << decimalToBinaryRecursive(0) << endl;
cout << decimalToBinaryRecursive(1) << endl;
cout << decimalToBinaryRecursive(8) << endl;
return 0;
}
See the output image below