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

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

## 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

## 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

## 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

Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,