cpp program decimal to binary

 conversion binary to decimal

In this program, you learn how to convert the binary numbers into decimal numbers in the cpp programming language.


For understanding this conversion you must have the knowledge of the following topics.

Following is the conversion code

code:
#include <iostream>
#include <cmath>
using namespace std;


int main()
{
    int num, binaryNumber,decimal;

    cout << "Enter a decimal number: ";
    cin >> num;
   
    decimal=num;
    
    int remainder, i = 1;

    while (num!=0)
    {
        remainder = num%2;
        num /= 2;
        binaryNumber += remainder*i;
        i *= 10;
    }
     
    cout << decimal << " in decimal = " << binaryNumber << " in binary" << endl ;
    return 0;
}

Output:

Enter a decimal number: 54
54 in decimal = 110110 in binary

Comments

Popular posts from this blog

Diferrence between flutter and react native

Flutter Widgets

Flutter layout