Program for Decimal to Binary Conversion

www.programmingcalculator.com
https://nikhilnihal.github.io/programmingcalculator/index.html

C++ Program for Decimal to Binary Conversion

#include<bits/stdc++.h>

using namespace std;

int main()
{
    long dec,rem,i=1,sum=0,binary=0;
    cout<<"Enter the decimal to be converted:";
    cin>>dec;

    while(dec!=0)
    {
      rem=dec%2;
      dec/=2;
      binary+=rem*i;
      i*=10;
    }

    cout<<"The binary of the given number is:"<<binary<<endl;

    return 0;
}

Comments

Popular posts from this blog

Getting Started With MEAN App Development with AngularJs , ExpressJs , NodeJs and MongoDB.

B. Dreamoon and WiFi :calculate no. of ways : recursive solution (branch and bound )

A. Dreamoon and Stairs : minimum steps to reach : recursion solution.