Advertisement
modlicha

Zamiana na różne systemy liczbowe (ze stackami)

Jan 30th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <stack> //biblioteka_stosa
  3.  
  4. using namespace std;
  5.  
  6. string dec2base(int dec, int base)
  7. {
  8. stack<int> s; //stos
  9. string temp = "";
  10.  
  11. while(dec!=0)
  12. {
  13. s.push(dec%base); //wrzucenie_na_stos
  14. dec/=base;
  15. }
  16.  
  17. while(!s.empty()) //wykrzyknik_to_zaprzeczenie
  18. {
  19.  
  20. temp += (char)(s.top()+'0');
  21. s.pop();
  22. }
  23. return temp;
  24. }
  25.  
  26. int main()
  27. {
  28. int dec;
  29. cin >> dec;
  30.  
  31. for (int i=2;i<=9;i++)
  32. cout << i << "-> " << dec2base(dec,i) << endl;
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement