# C C++ program to convert binary to decimal

## C C++ program to convert binary to decimal

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

C और C++ दोनों भाषाओं में महत्वपूर्ण अंतर क्या है जानने के लिए देखें—C vs C++

Procedure Oriented Programming (POP) और Object Oriented Programming (OOP) में अंतर जानने के लिए देखें—POP vs OOP

### C program to convert binary to decimal

``````#include<stdio.h>
int main()
{
int binary, decimal=0, digit, base=1;
printf("Enter binary number: ");
scanf("%d",&binary);
while(binary!=0)
{
digit=binary%10;
decimal=digit*base+decimal;
base=base*2;
binary=binary/10;
}
printf("Decimal number = %d",decimal);
return 0;
}``````

### C++ program to convert binary to decimal

``````#include<iostream>
using namespace std;
int main()
{
int binary, decimal=0, digit, base=1;
cout<<"Enter binary number: ";
cin>>binary;
while(binary!=0)
{
digit=binary%10;
decimal=digit*base+decimal;
base=base*2;
binary=binary/10;
}
cout<<"Decimal number = "<<decimal;
return 0;
}``````

### Output of C C++ program to convert binary to decimal

```Enter binary number: 110100
Decimal number = 52```
```Enter binary number: 1001110
Decimal number = 78```

Share it to: