Tvor0zhok

Рекурсия II

Feb 17th, 2021 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int sys2to10 (int n)
  5. { if (n == 0) return 0;
  6. else return sys2to10(n/10) * 2 + (n % 10); }
  7.  
  8. int sys10to2 (int n)
  9. { if (n == 0) return 0;
  10. else return sys10to2(n/2) * 10 + (n % 2) ; }
  11.  
  12. int main()
  13. {
  14. for (int i = 0; i <= 127; ++i)
  15. {
  16. int x = sys10to2(i);
  17. cout << x << '\t' << sys2to10(x) << '\n';
  18. }
  19.  
  20. return 0;
  21. }
  22.  
  23.  
  24.  
Add Comment
Please, Sign In to add comment