# C Program to convert Decimal to Binary Number devquora

Posted On: Jan 26, 2023 ### Overview:

As we know that time is the most important concern in our life. To do any task easily, We have to use software to perform it in a simpler manner. Software is a set of programs with related documents. The Software Program or Program is a set of instructions to do a specific task. First, of all, I want to explain What is Number System? Then, I will explain What is a Decimal Number? Furthermore, I will explain What is a Binary Number? After that, I will write the logic for conversion between Decimal to Binary numbers as a C Program.

### What is a Number System?

Number System is a system that is used to represent a number. There are mainly four types of Number System in computers such as Decimal Number System, Binary Number System, Octal Number System, and Hexa- Decimal Number System. Each Number System uses its own digits to represent a number. The repetition of digits does not matter. For instance, a Decimal Number System uses 10 digits i.e. 0,1,2,3,4,5,6,7,8,9 to represent a number. A Binary Number System uses 2 digits i.e. 1, 0 to represent a number, etc.

### What is a Decimal Number?

A Decimal Number System used to represent a Decimal Number. We can say that the radix or base of a Decimal Number System is 10. A Decimal Number is constructed with any digit from 0 to 9. A Decimal Number looks like a Mathematical number. For instance, 24 is a Decimal Number constructed from the digits 2 and 4. Furthermore, Decimal Number is a combination of any digits i.e. 0,1,2,3,4,5,6,7,8,9. There are various examples of Decimal numbers such as 124, 179, 111, 1245, etc.

### What is a Binary Number?

A Binary Number System used to represent a Binary Number. We can say that the radix or base of a Binary Number System is 2. A Binary Number is constructed with digits 0 and 1. A Computer can understand only binary language that is a mixture of Binary numbers. For instance, 11000 is a Binary Number constructed from the digits 1 and 0 which is the value of a Decimal Number 24. Moreover, 10, 11, 100, 101 are examples of the Binary NUmber.

### What is a Program?

A Program is a set of instructions to perform a specific task. A Program tells the Computer What to do? And a Logic tells the computer How to do it? To Write a Program We will construct our own logic related to the task.

### Demonstration of Conversion between Decimal to Binary Number.

• Step 1: Divide the Decimal number by 2 and store the remainder in an array.
• Step 2: Repeat Step 1 with the previous Quotient obtained by it until the 1.
• Step 3: At last Write the stored value of the array in reverse order to found the Binary Value.

Example: Conversion of Decimal Number 24 to Binary Number that is 11000.

QuotientQuotient/2Remainder Array
Step 1: Divide the given Decimal number by 2 and store the remainder into a remainder array.24/20
Step 2: Repeat Step 1 because Quotient is not 112/20
Step 3: Repeat Step 1 because Quotient is not 16/20
Step 4: Repeat Step 1 because Quotient is not 13/21
Step 3: Don't Repeat again Step 1 because Quotient is 111

Now, Array values are 0,0,0,1,1. Write the array values in descending order to show the binary value of 24 i.e. 11000.

### C Program that will convert the Entered Decimal Number to Binary Number.

```#include <stdio.h>
#include  <stdlib.h>
void main()
{
int r, decimal_Number, q;
system ("cls");
printf("Please! Enter the Decimal number to convert into Binary Number: ");
scanf("%d",&decimal_Number);
for(q=0; decimal_Number>0; q++)
{
r[q]=decimal_Number%2;
decimal_Number=decimal_Number/2;
}
printf("Binary equivalent of Entered Decimal Number is:");
for(q=q-1;q>=0;q--)
{
printf("%d",r[q]);
}
}
```

Save this program with the filename and extension .c like filename.c. Then compile it on turbo C or another compiler.

The output of the program looks like this:

Please! Enter the Decimal number to convert into Binary Number: 24

Binary equivalent of Entered Decimal Number is: 11000 Conclusion: Explanation of This Program with output. The internal working of this program depends upon the previous demonstration of Conversion between Decimal to Binary Number.

After the successful compilation of the program, a message is displayed on the screen as Please! Enter the Decimal number to convert into Binary Number: Suppose, User entered 24 then again a message is displayed as Binary equivalent of Entered Decimal Number is: 11000 with Binary equivalent of 24 i.e. 11000.

Never Miss an Articles from us.

## Related Articles

#### C program to reverse a string

This program reversed the entered string that means opposite of the previous string sequence...

#### C program to reverse an Integer number

Are you want a demonstration of The C Program that reverses an Integer number? This Program reversing the sequence of digits in an Integer. After the successful compilation of the program, a message..

#### C program to reverse any number by using function

This Program reversed any number such as Integer, float, or decimal in their equivalent. After the successful compilation of the program, a message is displayed on the screen as Please! Enter a string..