Decimal to binary program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; }

30th Jan 2017, 4:00 AM
Atul kumar
Atul kumar - avatar
1 Answer
+ 3
You should have posted this in "Codes" section.
2nd Feb 2017, 2:27 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar