Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

C-program to Convert Binary Number to Decimal Number and Vice-Versa




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
color>main()color>
{
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();
}



Don't just read, write it, run it.....color>

RESULT:color>






This post first appeared on ProgramJoy.blogspot.com, please read the originial post: here

Share the post

C-program to Convert Binary Number to Decimal Number and Vice-Versa

×

Subscribe to Programjoy.blogspot.com

Get updates delivered right to your inbox!

Thank you for your subscription

×