Advertisement
modlicha

Stacki(Biblioteka i wzory)

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