Define a recursive method dec2bin( ) which takes an integer argument, and print binary representation of given input.
#include<iostream>
using namespace std;
int dec2bin(int decimal_number)
{
if (decimal_number == 0)
return 0;
else
return (decimal_number % 2 + 10 *dec2bin(decimal_number / 2));
}
int main()
{
int decimal_number;
cout<<"ENTER DECIMAL NUMBER = ";
cin>>decimal_number;
cout <<"\nDecimal Number is = "<<decimal_number<<endl;
cout<<"\nConvert into Binary Number is = " <<dec2bin(decimal_number);
return 0;
}