codescracker


c++

C++ Program to Convert Decimal to Binary



« Previous Program Next Program »


Decimal to Binary Conversion in C++

To convert decimal number to binary number in C++ programming, you have to ask to the user to enter the decimal number to convert it into binary number to display the equivalent value in binary format as shown here in the following program.

C++ Programming Code Convert Decimal to Binary

Following C++ program ask to the user to enter any number in decimal format to convert it into binary, then display the result on the screen :

/* C++ Program - Decimal to Binary Conversion */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	long int decnum, rem, quot;
	int binnum[100], i=1, j;
	cout<<"Enter any decimal number : ";
	cin>>decnum;
	quot=decnum;
	while(quot!=0)
	{
		binnum[i++]=quot%2;
		quot=quot/2;
	}
	cout<<"Equivalent binary value of "<<decnum<<" :\n";
	for(j=i-1; j>0; j--)
	{
		cout<<binnum[j];
	}
	getch();
}

When the above C++ program is compile and executed, it will produce the following result:

C++ program convert decimal to binary

Same Program in Other Language

You may like the same program in other programming language:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test