Search This Blog

Program to Convert Decimal to Binary - Binary Converter Program

This is a C program to convert decimal numbers to Binary numbers. Binary number system is the base 2 number system. The digits used in this number system are 0 and 1 only. The program is as follows:


#include<stdio.h>
#include<string.h>

int DecToBin(int dec)
{
int bin=0;
int i=1,tnum,rem;
tnum=dec;
while(tnum!=0)
{
rem=tnum%2;
bin=i*rem+bin;
tnum/=2;
i*=10;
}
return(bin);
}


void main()
{
int inputnum;
printf("\nEnter the decimal number\n");
scanf("%d",&inputnum);
printf("Corresponding binary number is: %d",DecToBin(inputnum));
}

No comments: