Advertisement
allia

двоичная запись

Sep 17th, 2020
1,137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.   int a=0, n=2, c=0;
  9.   cin >> a;
  10.   while (a/n!=0)
  11.   { n*=2;
  12.     c++;
  13.   }
  14.   n=10;
  15.  
  16.   int arr[c+1];
  17.  
  18.   for (int i=0; i<=c; i++)
  19.   {
  20.     arr[i]=a%2;
  21.     a/=2;
  22.   }
  23.  
  24.   for (int i=c; i>=0; i--)
  25.      cout << arr[i] << " ";
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement