Write two recursive functions one should take as a paramete
Write two recursive functions - one should take as a parameter a C++ string of \'1\'s and \'0\'s that are the binary representation of a positive integer, and return the equivalent int value; the other should take as a parameter a positive int value, and return a C++ string of \'1\'s and \'0\'s that are the binary representation of that number (no leading zeros). The functions should be named binToDec and decToBin. Do not use any number base conversion functionality that is built into C++.
Solution
Decimal to Binary Conversion :
#include <iostream>
using namespace std;
void decToBin(int number);
int main()
{
int number;
cout << \"Enter a positive Decimal integer value: \";
cin >> number;
if (number < 0)
{
cout << endl << \"Invalid Entry.\" << endl << endl;
}
else
{
cout << endl << \"Decimal \" << number << \" = \";
decToBin(number);
cout << endl << endl;
}
return 0;
}
void decToBin(int number)
{
int orig_number=number;
int remainder;
remainder = number % 2;
number = number / 2;
if (number > 0)
{
decToBin(number);
}
else if (number = 0)
{
cout << \"0\";
return;
}
cout <<remainder;
}
Binary to Decimal Conversion :
#include <iostream>
using namespace std;
int binToDec(int num);
int main()
{
int bin_number;
cout << \"Enter a positive Binary value: \";
cin >> bin_number;
int dec=binToDec(bin_number);
cout<<\"Decimal Representation :\"<<dec;
return 0;
}
int binToDec(int num)
{
if (!(num / 10)) return (num);
return (num % 10 + binToDec(num / 10) * 2);
}

