Decimal to binary program | SoloLearn: Learn to code for FREE!

+3

Decimal to binary program

#include<iostream> using namespace std; void binary(int num) { int rem; if (num <= 1) { cout << num; return; } rem = num % 2; binary(num / 2); cout << rem; } int main() { int dec, bin; cout << "Enter the number : "; cin >> dec; if (dec < 0) cout << dec << " is not a positive integer." << endl; else { cout << "The binary form of " << dec << " is "; binary(dec); cout << endl; } return 0; }

1/30/2017 4:00:39 AM

Atul kumar

1 Answer

New Answer

+3

You should have posted this in "Codes" section.