C Program to Convert Decimal number into Binary Number

Program to Convert Decimal number into Binary : Number System : Download

Output :

Explanation of Program :

Always Program execution starts from main function. Inside Main function we are accepting the decimal number.

Now after accepting the input decimal number we pass the decimal number to function dec_bin(num) function using following syntax.

Inside the Function Call –

We have declared some variables and the use of each variable is listed in following table –

Variable Data Type Initial Value Use of Variable
rem[50] long int Garbage Storing the Remainder
i long int 0 Subscript Variable for Running Loop
length long int 0 Storing the Length of the Array

We are following steps until the number becomes 0 or less than 0 –
[box]Step 1 : Check Whether the Number is Less than or Equal to Zero [/box]
[box]Step 2 : Divide the number by 2 and store the remainder in the array [/box]

[box]Step 3 : Increase the length of the array by 1 and also increment the subscript variable[/box]
After the execution of while loop print the array in reverse order.

Download Decimal to Binary Code :

[box]Download Code [/box]