mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
decimal to binary conversion
This commit is contained in:
parent
c87361a5cc
commit
eeddc8af8a
20
decimal_to_binary.cpp
Normal file
20
decimal_to_binary.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user