C
x
19
1
2
3
void main()4
{5
int num, binary_val, decimal_val = 0, base = 1, rem;6
7
printf("Enter a binary number(1s and 0s) \n");8
scanf("%d", &num); 9
binary_val = num;10
while (num > 0)11
{12
rem = num % 10;13
decimal_val = decimal_val + rem * base;14
num = num / 10 ;15
base = base * 2;16
}17
printf("The Binary number is = %d \n", binary_val);18
printf("Its decimal equivalent is = %d \n", decimal_val);19
}$ gcc prog.c -Wall -Wextra -std=gnu11
Stdin
0000000000000101Start
prog.c:3:6: warning: return type of 'main' is not 'int' [-Wmain]
3 | void main()
| ^~~~
Enter a binary number(1s and 0s) The Binary number is = 101 Its decimal equivalent is = 5
31
Finish