Generating N | C ++ program Generating N - bit Gray Code starting from K ; Function to Generating N - bit Gray Code starting from K ; Generate gray code of corresponding binary number of integer i . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void genSequence ( int n , int val ) { for ( int i = 0 ; i < ( 1 << n ) ; i ++ ) { int x = i ^ ( i >> 1 ) ^ val ; cout << x << " ▁ " ; } } int main ( ) { int n = 3 , k = 2 ; genSequence ( n , k ) ; return 0 ; }