#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
long int d2b(int);
static long int binary=0;
static int i=0;
long int d2b(int num)
{
if(num!=0)
{
binary=binary+pow(10,i)*(num%2);
d2b(num/2);
i++;
}
return(binary);
}
int main()
{
int num;
long int binary_ans=0;
cout<<"Enter the number.";
cin>>num;
binary_ans=d2b(num);
cout<<"Ans = "<<binary_ans;
getch();
return(0);
}
I am using Dev C++ compiler and this code doesnt seem to work. Can somebody please run this code on their compilers and give me a feedback. Also if the code seems incorrect to you, please tell me the reason why you think so.