TheAlgorithms-C-Plus-Plus/decimal_to_binary.cpp

21 lines
262 B
C++
Raw Normal View History

2016-07-22 16:09:54 +08:00
#include<iostream>
using namespace std;
int main()
{
int number;
cin>>number;
int remainder,binary=0,var=1;
do{
remainder=number%2;
number=number/2;
binary=binary+(remainder*var);
var=var*10;
}
while(number>0);
cout<<binary;
}