Unnamed
public text v1 · immutable
#include "stdafx.h"
#include "math.h"
int bindec( int x, int y, int z); /* Function Prototype for the "binary" to decimal conversion */
int main(void)
{
int number;
int total = 0;
int power = 1;
printf("Enter a binary number: ");
scanf("%d", &number);
printf( "%d is %d in decimal.\n", number, bindec( number, total, power));
return 0;
}
/* The function bindec */
int bindec(int x, int y, int z)
{
while(x > 0)
{
y+(x%10)*z;
z = z*2;
x = x/10;
}
return y;
}