Convert Decimal to Binary in C
Get Certified in C Programming and Take Your Skills to the Next Level
Program 1
// Program for Binary to Decimal
#include<stdio.h>
#include<conio.h>
int main()
{
system("cls");
int n,dn=0,r,b=1,binary;
printf("Enter a binary no(only o and 1 format)");
scanf("%d",&n); // n= 1011
binary=n; //binary=1011
while(n!=0) // 1 !=0
{
r=n%10; // r=1
dn=dn+r*b; // dn=11
b=b*2; // b =16
n=n/10; //0
}
printf("\n Binary Number: %d",binary);
printf("\n Decimal Number: %d",dn);
return 0;
}
Did you like this article? If Yes, please give DataFlair 5 Stars on Google

