C program to convert Decimal number to Binary

Decimal number to Binary

C program to convert Decimal number to Binary number

First of all, we need to understand what is decimal numbers and binary numbers, if we know about these numbers is easy to convert decimal to binary.

Decimal Number

A decimal number is a base 10 number because it ranges from 0 to 9, there are a total of 10 digits between 0 to 9. Any combination of digits is a decimal number such as 23, 445, 132, 0, 2, etc.

Binary Number

The binary number is a base 2 number because it is either 0 or 1. Any combination of 0 and 1 is a binary number such as 1001, 101, 11111, 101010, etc.

Procedure

  • Divide the number by 2 through % (modulus operator) and store the remainder in array
  • Divide the number by 2 through / (division operator)
  • Repeat previous step until the number is greater than 0
#include<stdio.h>
#include<conio.h>    
#include<stdlib.h>  
void main(){  
int x[10],num,i;    
system ("cls");  
      printf("\n\t\t\t...Welcome To EduNews.Tech... ");

printf("\n\nEnter the number to convert: ");    
scanf("%d",&num);    
for(i=0;n>0;i++)    
  {    
    x[i]=num%2;    
    num=num/2;    
  }    
printf("\nBinary of Given Number is=");    
    for(i=i-1;i>=0;i--)    
      {    
         printf("%d",x[i]);    
      }    
    printf("\n\n\n\t\t\tThankyou for Joining Us !");
    printf("\n\t\t\t!Regards EduNews !");

getch();
}  

Program Output:

decimal to binary

I hope this post helps you to understand & “Convert Decimal number to Binary number” and its implementation in C programming language.

Keep coding 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *