66 982
Assignments Done
99,2%
Successfully Done
In November 2018

Answer to Question #39739 in C++ for Ayeza

Question #39739
a code on how to convert binary to decimal in c programming.
Expert's answer
#include <iostream>


int binaryToDecimal(int n)
{
int output = 0;


for(int i=0; n > 0; i++)
{
if (n % 10 == 1)
output += (1 << i);


n /= 10;
}


return output;
}


int main (void)
{
std::cout << "Enter binary number: ";
int binaryNumber;
std::cin >> binaryNumber;
std::cout << "Decimal: " << binaryToDecimal(binaryNumber) << std::endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions