# include # include using namespace std; void counting ( int n, int d[], int dmin, int dmax ) // // COUNTING will produce, one after another, all the arrays of N digits // with entries between DMIN and DMAX. // { int i, inc, step; for ( i = 0; i < n; i++ ) { d[i] = dmin; } step = 0; while ( true ) { // // Just to show what is going on, let's print the digits here. // step = step + 1; cout << " " << step; for ( i = 0; i < n; i++ ) { cout << " " << d[i]; } cout << "\n"; // // Try to increment the last digit. // inc = -1; for ( i = n - 1; 0 <= i; i-- ) { if ( d[i] == dmax ) { d[i] = dmin; } else { inc = i; d[i] = d[i] + 1; break; } } // // If INC is still -1, we didn't find anything to increment, and we are done! // if ( inc == -1 ) { break; } } return; }