fork(11) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void print (int res[], int n) {
  5. for (int i =0; i < n; i++) cout << res[i] << ' ';
  6. cout << endl;
  7. }
  8. void iterate(int d,int n,int size[], int res[]) {
  9. if (d >= n) { //stop clause
  10. print(res,n);
  11. return;
  12. }
  13. for (int i = 0; i < size[d]; i++) {
  14. res[d] = i;
  15. iterate(d+1,n,size,res);
  16. }
  17. }
  18.  
  19. int main() {
  20. int n = 3;
  21. int size[] = { 2, 4, 2};
  22. int res[3];
  23. iterate(0,n,size,res);
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
0 0 0 
0 0 1 
0 1 0 
0 1 1 
0 2 0 
0 2 1 
0 3 0 
0 3 1 
1 0 0 
1 0 1 
1 1 0 
1 1 1 
1 2 0 
1 2 1 
1 3 0 
1 3 1