Program in C++ to convert a decimal number into binary

By: Prof. Dr. Fazal Rehman | Last updated: February 11, 2025

C++ program to convert a decimal number to a binary number.
Output enter any number which is greater than 0: 3 output in form of the binary number is: 11
c++ program to convert a number into binary
c++ program to convert a number into binary
c++ convert a number into binary
c++ convert a number into binary
decial to binary c++ conversion
decimal to binary c++ conversion
dry-run-explanation-of-C-program-to-convert-a-decimal-to-binary-.webp
dry-run-explanation-of-C-program-to-convert-a-decimal-to-binary-.webp
c-example-to-convert-decimal-to-binary-using-array
c-example-to-convert-decimal-to-binary-using-array
program-in-c-to-convert-decimal-to-binary-with-array
How to convert decimal-to-binary-using-array in c++
How to convert decimal-to-binary-using-array in c++
explanation of decimal-to-binary c++
explanation of decimal-to-binary c++

Write a program in C++ to convert a decimal number into binary without using an array.

INTEGER PART QUOTIENT REMAINDER REMAINDER IN QUOTIENT
4/2 2 0 0
2/2 1 0 0
1/2 0 1 1
(4)10  = (100)2

Flowchart of decimal number into binary without using an array

Flowchart of decimal number into binary without using an array
Figure: Flowchart of decimal number into binary without using an array
 

C++ code of decimal number into binary using do-while loop

Output enter decimal no: 7 the binary no is: 11

Exercise

Find the possible mistakes in the following Shamil’s Flow Table of the program of decimal number into binary using a do-while loop.
Loop   Condition What lines will execute Actual work        
1 time J=4 4>0   1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16   J=n,n=4,i=1,bin=0 Bin=0+(4%2)*1=0 i=1*10=10 n=4/2=2
2 time J=4 J=j/2=4/2 J=2 2>0   True 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 17, 10, 11, 12, 13, 14, 15, 16   Bin=0+(2%2)*10=0 i=10*10=100 n=2/2=1  
3 time J=2 J=2/2 J=1 1>0   True   1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 17, 10, 11, 12, 13, 14, 15, 16 17,10,11,12,13,14,15,16   Bin=0+(1%2)*100=100 i=100*10=1000 n=1/2=0  
4 time J=1 J=1/2 J=0 0>0   False   1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 17, 10, 11, 12, 13, 14, 15, 16 17,18, 19   Print binary =100

C++ code of decimal number into binary using while loop

Decimal number into binary using for loop in C++

Write a program in C++ to convert a decimal number into a binary number using for loop. Output Please Enter the number to convert: 8 Binary of the given number= 1000 shamil memory table

Leave a Comment

All Copyrights Reserved 2025 Reserved by T4Tutorials