BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to Convert Decimal Number to Binary Number

Last Updated: September 25, 2017 by Chaitanya Singh | Filed Under: C Programs

This program converts a decimal number to an equivalent binary number.

Example: Program to convert Decimal to Binary

In this program, we have created a user defined function decimalToBinary() for decimal to binary conversion. The programs takes decimal number (entered by user) as input and converts it into a binary number using the function decimalToBinary(). To understand this program, you should have the basic idea of following C programming topics:

  1. C – Functions
  2. C – while loop
#include <stdio.h>
#include <math.h>

long decimalToBinary(int decimalnum)
{
    long binarynum = 0;
    int rem, temp = 1;

    while (decimalnum!=0)
    {
        rem = decimalnum%2;
        decimalnum = decimalnum / 2;
        binarynum = binarynum + rem*temp;
        temp = temp * 10;
    }
    return binarynum;
}

int main()
{
    int decimalnum;
    printf("Enter a Decimal Number: ");
    scanf("%d", &decimalnum);
    printf("Equivalent Binary Number is: %ld", decimalToBinary(decimalnum));
    return 0;
}

Output:

Enter a Decimal Number: 234
Equivalent Binary Number is: 11101010

Check out these related C Programs:

  1. C Program to convert Decimal to an Octal number
  2. C Program to convert Octal to a Decimal number
  3. C Program to convert Octal number to a binary number
  4. C Program to convert Binary to an Octal Number
  5. C Program to convert a Binary number to a decimal Number

Top Related Articles:

  1. C Program to find the Average of two numbers
  2. C Program to Convert Binary to Octal Number System
  3. C Program to check whether a given integer is positive or negative
  4. C Program to Convert Octal Number to Decimal Number
  5. C Program to Convert Octal Number to Binary Number

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

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

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap