Tuesday, August 10, 2010

BINARY TO DECIMAL CONVERSION

0 comments


#include<stdio.h>
#include<stdio.h>  
#include<stdio.h>
void main()
{
int i=0,num,decimal=0;
long n;
printf("Enter the binary number:");
scanf("%d",&n);
while(n>0)

num=n%10;
decimal=decimal+num*pow(2,i);
n=n/10;
i=i+1;
}
printf("The decimal number is %d",decimal);
getch();
}







Algorithm:

1.Start.
2.Read the binary number,n
3.Calculate ai2n-1+ai2n-2+ai2n-3+..................+ai2
4.Print the decimal equivalent of the binary.
5.Stop.

Leave a Reply