## 15. C PROGRAMMING LAB | Check Now

VTU C PROGRAMMING LAB – 15] Write a Program to Convert a Binary Number into a Decimal Number.

## 15. C PROGRAMMING – Algorithm

• Step-1: Start
• Step-2: Read the binary number value
• Step-3: Call the function find by passing arguments
• Step-4: Check if number entered is zero than return 0 otherwise compute using formula-
• ( pow ( 2, count ) * ( x % 10 ) + find ( x /10 , count + 1 ) )
• Step-5: Repeat the step-4 until recursive condition find becomes false
• Step-6: Return the result of converted number
• Step-7: Stop

## C PROGRAMMING -15 Program source code

```#include <stdio.h>
#include <math.h>
int find(int x, int count)
{
if (x == 0)
return 0;
else
return(pow(2, count) * (x%10 ) + find(x/10 ,count+1));
}
void main()
{
int binary;
printf("Enter a Binary number");
scanf ("%d",&binary);
printf(" The decimal value for binary %d is",binary);
printf("%d", find(binary,0));
}```

## Output

Enter a Binary number

1010

The decimal value for binary number 1010 is 10

## C PROGRAMMING Viva Questions

1] What is the binary?

2] What is meant by a binary number system?

3] How do you construct an increment statement or decrement statement in C?

4] What is variable initialization and why is it important?

5] What is the differnce between the = (equal) symbol and == (double equal) symbol?