Program To Convert A Decimal Number To A Binary Number Using Array In C/C++

LEVEL: Beginner

Whats in this post?

  1. Code
  2. Output
  3. Background and Explanation of the code
  4. Download Code

Code


To copy code: Click   “View Source” on the right of this code snippet.


Background and Explanation of the code


1. In this program we enter a decimal number 62. Now we go on dividing the entered number by 2 and store the result in the array.

Therefore , a[0] = 0, a[1] = 1,. . . . . . a[5] = 1

then we print the elements of array in reverse order and get the result.

Output:

Enter the decimal number : 62 (Press Enter)

The binary equivalent is: 111110