WAP in C to Convert the Binary Number into Decimal Number ?

#include <stdio.h>
#include<conio.h>
void main()
{
int num, binary, decimal = 0, base = 1, rem;
clrscr();
printf(“Enter a binary number(1s and 0s) \n”);
scanf(“%d”, &num); /* maximum five digits due to range of integer */
binary = num;
while (num > 0)
{
rem = num % 10;
decimal = decimal + rem * base;
num = num / 10 ;
base = base * 2;
}
printf(“The Binary number is = %d \n”, binary);
printf(“Decimal equivalent is = %d \n”, decimal);
getch();
}

Output :-

BinToDec

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s