Name: Anonymous 2012-04-01 10:14
Hello /prog/, I need a help in understanding this code, anyone willing to explain it in detail to an idiot?
(decimal to binary number)
int main()
{
int dec,rem,i=1,sum=0;
cout<<"Enter the decimal to be converted:"<<endl;
cin>>dec;
do
{
rem=dec%2;
sum=sum + (i*rem);
dec=dec/2;
i=i*10;
}while(dec>0);
cout<<"The binary of the given number is:"<<sum<<endl;
}
(decimal to binary number)
int main()
{
int dec,rem,i=1,sum=0;
cout<<"Enter the decimal to be converted:"<<endl;
cin>>dec;
do
{
rem=dec%2;
sum=sum + (i*rem);
dec=dec/2;
i=i*10;
}while(dec>0);
cout<<"The binary of the given number is:"<<sum<<endl;
}