C program to convert decimal to binary number

 In this example, we will learn how to convert decimal to binary number system in a c programming language. Following is the solution to the problem.


#include <math.h>

#include <stdio.h>

int main() {

    int num,original;

    printf("Enter a decimal number: ");

    scanf("%d", &num);


     long long binary = 0;

    int remainder, i = 1;

    while (num != 0) {

        remainder = num % 2;

        num /= 2;

        binary += remainder * i;

        i *= 10;


    printf("%d in decimal = %lld in binary", original, binary);

    return 0;




Enter a decimal number: 15

15 in decimal = 1111 in binary


Hire a programmer

Popular posts from this blog

Python program to print Hello wolrd

input by cin in c++

pre increment or post increment in c++