Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

stack2.

cpp http://localhost:49839/9f824a04-64f9-4771-a714-d613e082a553/

c++\stl\stack2.cpp

1 //chuyen doi co so nguyen cua x tu he 10 sang co so n


2 //hien thi du lieu ra man hinh
3
4 #include <iostream>
5 #include <stack>
6 using namespace std;
7
8 int main()
9 {
10 int x;
11 cout << "Nhap so o he co so 10 : ";
12 cin >> x;
13
14 int n;
15 cout << "Nhap co so n: ";
16 cin >> n;
17
18 stack<int> xSau;
19 while(x != 0)
20 {
21 xSau.push(x%n);
22 x = x / n;
23 }
24
25 cout << "So ay o he co so " << n << " la: ";
26 stack<int> s2;
27 s2 = xSau;
28 while(!s2.empty())
29 {
30 cout << s2.top();
31 s2.pop();
32 }
33
34 }

1 trong 1 25/01/2024, 23:23

You might also like