In this C-program we will Convert the Binary Number into Decimal number and Decimal Number into Binary Number. The number will be taken from the user.color>
input:
The number.(i.e : 5,6,9[Decimal Number] or 1100,1010,1111[Binary Number] etc.)output:
Binary number will be converted into Decimal number OR Decimal number will be converted into Binary number.CODE---->
#include
#include
#include
{
long long bin_num,bin;
int dec_num,dec,remainder,i,n;
printf("***************Welcome to Converter***************color>");
printf("\n\n\n1.Binary to Decimal\n\n2.Decimal to Binary\n\n Enter Your choice : color>");
scanf("%dcolor>",&n);
switch(ncolor>)
{
case 1color>:
printf("\nPlease, Enter the Binary number : color>");
scanf("%lldcolor>",&bin_num);
bin=bin_num;
i=0;
dec=0;
while(bin_num!=0color>)
{
remainder=bin_num%10;
dec=dec+remainder*pow(2color>,icolor>);
i++;
bin_num=bin_num/10;
}
printf("\nThe decimal of %lld is : %dcolor>",bin,dec);
break;
case 2color>:
printf("\nPlease, Enter the Decimal number : color>");
scanf("%dcolor>",&dec_num);
dec=dec_num;
i=1;
bin=0;
while(dec_num!=0color>)
{
remainder=dec_num%2;
dec_num=dec_num/2;
bin=bin+remainder*i;
i=i*10;
}
printf("\nThe binary of %d is : %lldcolor>",dec,bin);
break;
default:
printf("\n SORRY !!! You have Entered a wrong choice.color>");
break;
}
getch();
}
color>