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