C Program to convert binary todecimal number

Sample Input 1:

1010

Sample Output 1:

10

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#include<stdio.h> int main() { //write your code here }

Program or Solution

				
			
					
#include <stdio.h>
 
int main()
{
	int binary_val, decimal_val = 0, base = 1, rem;
 	printf("Enter a Binary Number:");
    	scanf("%d", &binary_val); 
    	while (binary_val > 0)
    	{
        	rem = binary_val % 10;
        	decimal_val = decimal_val + rem * base;
        	binary_val = binary_val / 10 ;
        	base = base * 2;
    	}
    	printf("Equivalent Decimal number is %d", decimal_val);
    	return 0;
}
			
				
			

Program Explanation

yet to be updated

Comments


Related Programs