rendom number genrator decimal to binary system 0 to n

#include <iostream>
#include <stdlib.h>
using namespace std;
long decimal(long);
int main()
{
long dec,ren;
cout<<"Enter the decimal to be converted:";
cin>>dec;
for(long j=1;j<=dec;j++)
{
ren=1 + (rand() % dec);
decimal(ren);
}
cin.get();
return 0;
}

long decimal(long dec)
{
long rem,sum=0,i=1,num;
num=dec;
do
{
rem=dec%2;
sum=sum + (i*rem);
dec=dec/2;
i=i*10;
}while(dec>0);

cout<<" "<<num<<" -> "<<sum<<endl<<endl;
}
What is the question?
Topic archived. No new replies allowed.