#include #include #include void print_gray(unsigned char * massiv, unsigned int size) { for (int i=(size-1); i>=0; --i) printf("%d",massiv[i]); }; void generate_gray(unsigned int n,unsigned int k) { unsigned char * gray_digit = (unsigned char *) malloc(sizeof(unsigned char)*k); int i,p,j; memset(gray_digit,0,sizeof(unsigned char)*k); i = 0; do { print_gray(gray_digit,k); printf(" - :%d\n", i); ++i; if(i>n) break; p=0; j=i; while ( j%2 == 0) { j = j/2; ++p; }; if (p < k) gray_digit[p] = 1 - gray_digit[p]; }while( p < k ); free(gray_digit); }; int main() { unsigned int k,n; printf("Input k (bits length):"); scanf("%d",&k); printf("Input n (num iteration):"); scanf("%d",&n); generate_gray(n,k); return 0; }