Guest User

Untitled

a guest
Oct 28th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. void printGreeting()
  8. {
  9.     cout << "эта программа переводит числа из десятичного вида в двоичный" << endl;
  10.     cout << "введите число ";
  11. }
  12.  
  13. vector<int> toBin(int number)
  14. {
  15.     vector<int> array;
  16.  
  17.     for (int i = 0; number != 0; i++, number /= 2)
  18.     {
  19.         if (number % 2 != 0)
  20.             array.push_back(0);
  21.         else
  22.             array.push_back(1);
  23.     }
  24.  
  25.     return array;
  26. }
  27.  
  28. int main()
  29. {
  30.     printGreeting();
  31.  
  32.     int input;
  33.     cin >> input;
  34.  
  35.     vector<int> array = toBin(input);
  36.     for_each(array.rbegin(), array.rend(), [](int num) { cout << num; });
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment