We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 3f2e159 + 5a3e5a5 commit 23c8357Copy full SHA for 23c8357
Stack/Binary numbers/Question.txt
@@ -0,0 +1 @@
1
+The question is how to make binary numbers using a stack.
Stack/Binary numbers/solution.cpp
@@ -0,0 +1,27 @@
+#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