This is a simple C++ code that converts any decimal number into binary number system. The program takes input from user in decimal number form and return output in binary number system using a recursive function that takes decimal number as a parameter for it.
The C++ program is successfully compiled and run on a Windows OS system using Microsoft’s Visual Studio 2013.
Enter any decimal number: 2
After converting 2 in binary form 0010
//Program to Convert Decimal number into Binary number
using namespace std;
void binary(int num)
if (num <= 1)
cout << num;
rem = num % 2;
binary(num / 2);
cout << rem;
int dec, bin;
cout << “Enter any decimal number : “;
cin >> dec;
if (dec < 0)
cout << dec << ” Seems not a positive number. Try another one next time.” << endl;
cout << “After converting ” << dec << ” into binary form: “;
cout << endl;
Write in below comments if you have any tutorial request or have any assignment pending from your college. How Strings will get back to you for your help as soon as possible. Follow How Strings for more tech tutorials!