A programe to convert binary into decimal using Function.
#include<conio.h>
#include<stdio.h>
void convert(int );
void main()
{
int num;
printf("Enter a binary number(1s and 0s) \n");
scanf("%d", &num);
convert(num);
getch();
}
void convert(int num )
{
binary_val = num;
while (num > 0)
{
rem = num % 10;
decimal_val = decimal_val + rem * base;
num = num / 10 ;
base = base * 2;
}
printf("The Binary number is = %d \n", binary_val);
printf("Its decimal equivalent is = %d \n", decimal_val);
}
Enter a binary number(1s and 0s)
Comments
Post a Comment