Skip to content

Commit 23c8357

Browse files
authored
Merge pull request ashutosh97#192 from zomsik/master
Added a question and answer to convert decimal numbers to binary numbers
2 parents 3f2e159 + 5a3e5a5 commit 23c8357

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Stack/Binary numbers/Question.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The question is how to make binary numbers using a stack.

Stack/Binary numbers/solution.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <iostream>
2+
#include <stack>
3+
using namespace std;
4+
int main()
5+
{
6+
int a,b,l,c;
7+
stack <int> stos;
8+
cout << "Number to change: ";
9+
cin >> a;
10+
l=a;
11+
12+
while(a!=0)
13+
{
14+
b=a%2;
15+
a=a/2;
16+
stos.push(b);
17+
}
18+
cout << "Number " << l << " is equal to: ";
19+
while(!stos.empty())
20+
{
21+
cout << stos.top();
22+
stos.pop();
23+
}
24+
cout << " in binary system.";
25+
26+
return 0;
27+
}

0 commit comments

Comments
 (0)