Home C Language Basic C Programs Decimal to Binary in C

Decimal to Binary in C

Write a program in C to convert decimal number to binary number using the function.

#include <stdio.h>

void dectobin(long int);

void main()


    long num;

    printf(“Enter a decimal integer: “);

    scanf(“%ld”, &num);



void dectobin(long intdec_num)


    int i=0,remainder;

    char bi[1024];

    while (dec_num> 0)


        remainder = dec_num % 2;


        dec_num = dec_num / 2;


    printf(“Its binary equivalent is: “);





Enter a decimal integer: 95

Its binary equivalent is: 1011111