C Program for Base Conversion from Decimal to Binary

The decimal (base tennumeral system has ten possible values (0,1,2,3,4,5,6,7,8, or 9) for each place-value. In contrast, the binary (base twonumeral system has two possible values, often represented as 0 or 1, for each place-value

the base of each individual number may be specified by writing it as a subscript of the number. For example, the decimal number 156 may be written as 15610 and read as “one hundred fifty-six, base ten”. The binary conversion of 156 is 10011100 may be specified as “base two” by writing it as 100111002.

Code:

//C Program to Convert Decimal to Binary
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i=0,b[100],j;
clrscr();
printf(“Enter decimal number: “);
scanf(“%d”,&n);
while (n>0)
{
b[i]=n%2;
n=n/2;
i++;
}
printf(“Binary is: “);
j=i-1;
for (i=j;j>=0;j–)
{
printf(“%d”, b[j]);
}
getch();

}

Also Read:

C Program for Base Conversion from Binary to Decimal

Hope you liked my posts, give comments if you have any doubts… 🙂

——————————————————————————————————————————————————————————–

Tags:

Leave a comment