CPP Program to convert Decimal Number into Binary Number

The program takes any integer number from the standard input device ( keyboard) and convert that number into its equvalant binary number using division method. This program was tried and tested on Dev C++ IDE.  Here is the source code of the same program.

/*	program to convert any decimal number into its equvalent binarynote
	made by		: rakesh kumar
*/
#include
#include
using namespace std;
int main()
{
	int n, bin[100];
	bin[0]=-1;
	int rem,i=0;
	//input phase
	cout<<"\n Enter any number : "; cin>>n;
	//processing phase
	while(n!=0)
	 {
	 	rem = n%2;
	 	bin[i++]=rem;
	 	n = int(n/2);
	 }
	//output phase
	cout<<"\n Binary No. : "; for(i=i-1;i>=0;i--)
	   cout<<bin[i];
	return 0;
}

The output of the same program is here. 
Decimal to binary converter

Related Posts

If you like CBSEToaday and would like to contribute, you can also write an article using submit article or mail your article to contribute@cbsetoday.com See your article appearing on the cbsetoday.com main page and help other students/teachers.