Skip to content

Commit 1e80c5d

Browse files
Merge pull request #258 from ankurdcruz/patch-1
DecimalToBinary.cpp
2 parents 512a854 + 685d506 commit 1e80c5d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

DecimalToBinary.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int n;
6+
long long int ans=0;
7+
cin>>n;
8+
int temp=n;
9+
int pv=1;
10+
int rem=1;
11+
while(temp)
12+
{
13+
rem=temp%2;
14+
ans+=pv*rem;
15+
pv=pv*10;
16+
temp=temp/2;
17+
}
18+
cout<<ans;
19+
}

0 commit comments

Comments
 (0)