C++ Program to perform Decimal to Binary Conversion [DEVCPP/GCC]

PROGRAM

// Program to perform Decimal to Binary Conversion

#include <iostream>

using namespace std;

int main()
{
        long dec,num;
        int bin[30],i=0,j,rem;

        cout<<"ENTER DECIMAL VALUE: ";
        cin>>dec;

        while(dec>0)
        {
                rem=dec%2;
                bin[i]=rem;
                dec=dec/2;
                i++;
        }

        cout<<"\nBINARY EQUIVALENT: ";

        for(j= (i-1) ; j>=0 ; j--)
        {
                cout<<bin[j];
        }

         return 0;
}

OUTPUT

C++ Program to perform Decimal to Binary Conversion with output

Share this

Related Posts

FIND US ON FACEBOOK!