C program to convert decimal number to binary number.

Posted by Mangesh on March 14, 2018

/* C program to convert decimal to binary. */

Description :

Decimal Number :
The number which comprises of 10 symbols are called Decimal Number. Those symbols are 0, 1,2, 3, 4, 5, 6, 7, 8, 9 .

Binary Number :
The number which comprises of 2 symbols are called Decimal Number. Those symbols are 0, 1 .

Program :

#include<stdio.h>
#include<conio.h>
void dectobin(int num)
{
  if(num==0)
   printf("0");
   else
   {
      dectobin(num/2);
      if(num%2==0)
        printf("0");
       else
        printf("1");
    }
}
void main()
{
  int number;
  printf("Enter the number: ");
  scanf("%d",&number);
  printf("binary representation of %d is ");
  dectobin(number);
  getch();
}

Output :

output of c program for decimal to binary converion` tested in turbo c 3.2

Skills Required :

Condition operators.
If-Else statement.
Understanding of recursion.

Written with from Mangesh.

Related Post
1 C program to calculate factorial of given number.
2 C program to convert decimal number to binary number.
3 C program to find the G.C.D. of two number.
Latest Post
1 C program to implement Queue using linked list.
2 C program for binary search tree (BST).
3 C program to search an element in linked list.
4 C program for postorder traversal in binary tree.
5 C program for preorder traversal in binary tree.