c program to convert decimal to binary - C++ coding

Here is the answer to the question asked for Writing a C++ program to convert a decimal number given by the user to binary. This program is tested in DEV C++.

Here is the answer to the question asked for Writing a C++ program to convert a decimal number given by the user to binary. This program is tested in DEV C++.

## c program to convert decimal to binary

#include <iostream>
using namespace std;
int main()
{
long dec,rem,i=1,sum=0;
cout<<"Enter the decimal Number to be converted:";
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;
cin.get();
cin.get();

return 0;
}
It's so simple. Here is the output we get:

 Output of the conversion

Name

ltr
item
MindxMaster: c program to convert decimal to binary - C++ coding
c program to convert decimal to binary - C++ coding
Here is the answer to the question asked for Writing a C++ program to convert a decimal number given by the user to binary. This program is tested in DEV C++.
https://2.bp.blogspot.com/-sH3Emd8-IN0/Vrcv0Vu7AVI/AAAAAAAABd4/qDhGwauxPHc/s1600/Untitled.jpg
https://2.bp.blogspot.com/-sH3Emd8-IN0/Vrcv0Vu7AVI/AAAAAAAABd4/qDhGwauxPHc/s72-c/Untitled.jpg
MindxMaster
http://www.mindxmaster.com/2016/02/simple-c-program-to-convert-decimal-to.html
http://www.mindxmaster.com/
http://www.mindxmaster.com/
http://www.mindxmaster.com/2016/02/simple-c-program-to-convert-decimal-to.html
true
5332415103371288268
UTF-8