Advertisement
Guest User

sds

a guest
Mar 29th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. void decToBin(int tab[], int n, int liczba) {
  8.  
  9.         int c = (n + 2) / 2;
  10.  
  11.         int d = 1, bit = 1;
  12.  
  13.         for (int i = 0; i < c; i++) {
  14.  
  15.                 if (liczba&d) {
  16.  
  17.                         bit = 1;
  18.  
  19.                 }
  20.  
  21.                 else { bit = 0; }
  22.  
  23.                 tab[(n / 2)-i] = bit;
  24.  
  25.                 tab[((n + 1) / 2)+i] = bit;
  26.  
  27.                 d <<= 1;
  28.  
  29.         }
  30.  
  31.         for (int i = 0; i < n + 1; i++) {
  32.  
  33.                 cout << tab[i];
  34.  
  35.         }
  36.  
  37. }
  38.  
  39. int rek(int c, int m) {
  40.  
  41.         int *tab = new int[c];
  42.  
  43.         if (m < 0)return 0;
  44.  
  45.         decToBin(tab, c-1, m);
  46.  
  47.         delete tab;
  48.  
  49.         rek(c,m-1);
  50.  
  51.         return 0;
  52.  
  53. }
  54.  
  55. int main() {
  56.  
  57.         int n,m;
  58.  
  59.         for (int i = 0; i < 50; i++) {
  60.  
  61.                 cin >> n;
  62.  
  63.                 m = (n + 1) / 2;
  64.  
  65.                 double liczba = pow(2.0, m) - 1;
  66.  
  67.                 rek(n, liczba);
  68.  
  69.                 cout << endl;
  70.  
  71.         }
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement