C++ Online Compiler
Example: C++ program to convert decimal to binary without using array
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ program to convert decimal to binary without using array #include <iostream> using namespace std; // The main function of the program int main() { // Step-1 Declare variables int num; long long binary = 0; int place = 1; // Step-2 Input decimal number cout << "Enter a decimal number: "; cin >> num; // Step-3 Convert to binary without using array while (num != 0) { int remainder = num % 2; binary += remainder * place; num /= 2; place *= 10; } // Step-4 Output the binary number cout << "Binary representation: " << binary << endl; return 0; }
Output
Clear
ADVERTISEMENTS