C++ Program that convert a number enter by a user to Binary number - 6 Players blogs for technology

give us your feedback

People Online

Breaking

ads

Post Top Ad

Tuesday, October 22, 2019

C++ Program that convert a number enter by a user to Binary number


C++ Program that convert a number enter by a user to Binary number 




#include <iostream>

using namespace std;

int main()
{
    long dec,reminder,num,base=1,binary=0;

    cout<< "Enter the number in Decimal : ";
    cin>>dec;
num=dec;

    while(dec>0)
    {
        reminder=dec%2;
        binary+=reminder*base;
        dec/=2;
        base*=10;
    }
    cout<< "Decimal"<< "\t"<< "Binary"<<endl;
    cout<<num<< "\t"<<binary<<endl;

    return 0;
}




No comments:

Post a Comment

ads1

Post Top Ad