Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <math.h>
- using namespace std;
- void decToBin(int tab[], int n, int liczba) {
- int c = (n + 2) / 2;
- int d = 1, bit = 1;
- for (int i = 0; i < c; i++) {
- if (liczba&d) {
- bit = 1;
- }
- else { bit = 0; }
- tab[(n / 2)-i] = bit;
- tab[((n + 1) / 2)+i] = bit;
- d <<= 1;
- }
- for (int i = 0; i < n + 1; i++) {
- cout << tab[i];
- }
- }
- int rek(int c, int m) {
- int *tab = new int[c];
- if (m < 0)return 0;
- decToBin(tab, c-1, m);
- delete tab;
- rek(c,m-1);
- return 0;
- }
- int main() {
- int n,m;
- for (int i = 0; i < 50; i++) {
- cin >> n;
- m = (n + 1) / 2;
- double liczba = pow(2.0, m) - 1;
- rek(n, liczba);
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement