Decimal to Binary in C++
###### Posted by Samath
Last Updated: December 26, 2014

Write a program that prompts the user to enter a decimal integer and displays its corresponding binary value.

Solution:

```#include <iostream>
#include <cstdlib>

using namespace std;
void binary(int);

int main(int argc, char *argv[])
{
int num;

cout << "Enter a decimal number: ";
cin >> num;

cout<<num;
cout<<" in decimal system is equal to ";
binary(num);cout<<" in binary system.\n\n";
}

void binary(int num)
{
int remainder;

if(num <= 1)
{
cout << num;
return;
}

remainder = num%2;
binary(num >> 1);

cout << remainder;
}```

###### Python Convert Decimal to Binary or Binary to Decimal
Samath | Jan 09, 2017
###### Binary to Decimal Conversion in C#
Samath | Jan 10, 2021
###### Python to Convert Decimal to Binary, Octal and Hexadecimal
gideonna | Apr 13, 2016
###### SQL Display two digits after decimal point
SceDev | Feb 08, 2024
###### How do you use the BINARY_CHECKSUM function to generate a hash value for a binary data?
PaulAnd | Jun 21, 2024
###### How do you use the BINARY data type to store binary data?
MaryJns | Jul 11, 2024
###### Convert Roman numerals to decimal using Java
Samath | Jan 17, 2024
###### Converting Time To Decimal using C++
Samath | Jan 04, 2017
###### C++ Convert from Decimal to Octal
Samath | Jan 05, 2017
###### C++ program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer
Samath | Apr 06, 2022
###### C++ program that prompts the user to input five decimal numbers, prints the five decimal numbers, converts each decimal number to the nearest integer, adds the five integers and prints the sum and average of the five integers.
Samath | Apr 06, 2022
###### Binary Search Tree in C++
Samath | Jan 07, 2021
###### How to add and retrieve record in a binary file using C++
Samath | Jan 06, 2021
###### C program that takes as input a positive fractional number and converts it to binary
Samath | Jan 01, 2017