x2311

Untitled

Dec 22nd, 2021 (edited)
1,261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <bitset>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. typedef unsigned char uc;
  8. const int size_uc = 8 * sizeof(uc);
  9.  
  10.  
  11. uc Gray(const uc &n) {
  12.     return (n ^ (n >> 1));
  13. }
  14.  
  15.  
  16. int main() {
  17.     cout << "n:";
  18.     int n;
  19.     cin >> n;
  20.     for (int i = 0; i < pow(2, n); ++i) cout << bitset<size_uc>(Gray(i)) << endl;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment