+ 7
Binary to decimal in C
i am stuck with my binary to decimal program in C. can u help me to solve
8 Respuestas
+ 8
Thank u my friend:-)
+ 8
👍
+ 7
actually i dnt have link.
+ 7
do u hav a ans with u Mr.Ram Krishna
+ 4
I hope this will works
+ 3
hiii nandhini
+ 3
#include <stdio.h>
void main()
{
int num, binary_val, decimal_val = 0,
base = 1, rem;
printf("Enter a binary number(1s and 0s) \n");
scanf("%d", &num);
binary_val = num;
while (num > 0)
{
rem = num % 10;
decimal_val = decimal_val + rem * base;
num = num / 10 ;
base = base * 2;
}
printf("Its decimal is = %d \n", decimal_val);
}