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;
}
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
Post a Comment