Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. int n = 0;
  7. int tab[8];
  8. cout << "Podaj liczbe: ";
  9. cin >> n;
  10. int i = 0;
  11. do {
  12. if (n % 2 == 0) {
  13. tab[i] = 0;
  14. i++;
  15. n = n / 2;
  16.  
  17. }
  18. if (n % 2 == 1) {
  19. tab[i] = 1;
  20. i++;
  21. n = n / 2;
  22.  
  23. }
  24.  
  25. } while (n != 0);
  26.  
  27.  
  28. int k = i;
  29.  
  30. for (int j = k-1; j >= 0; j--) {
  31. cout <<" "<< tab[j];
  32. }
  33.  
  34. getchar();
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement