Math, asked by djbarwo6689, 10 months ago

Write a c++ program to convert any binary number into its equivalent decimal number

Answers

Answered by vaibhav6853
0

Answer:

#include<iostream>

using namespace std;

int main ()

{

int num, rem, temp, dec = 0, b = 1;

cout << "Enter the binary number : ";

cin >> num;

temp = num;

while (num > 0)

{

rem = temp % 10;

dec = dec + rem * b;

b *= 2;

temp /= 10;

}

cout << "The decimal equivalent of " << num << " is " << dec;

return 0;

}

Step-by-step explanation:

let me know if it's clear

Similar questions