fork download
  1. #include <iostream>
  2. using namespace std;
  3. #include<vector>
  4.  
  5. void func(vector<vector<int> > arr,int row,vector<int> &temp,vector<vector<int> > &ans)
  6. {
  7. if(row>=arr.size())
  8. {
  9. ans.push_back(temp);
  10. return;
  11. }
  12. for(int i=0;i<arr[row].size();i++)
  13. {
  14. temp.push_back(arr[row][i]);
  15. func(arr,row+1,temp,ans);
  16. temp.pop_back();
  17. }
  18. }
  19.  
  20. int main()
  21. {
  22. vector<int> temp;
  23. vector<vector<int> > ans;
  24. vector<vector<int> > arr(3,vector<int>(3));
  25. arr[0][0]=1;arr[0][1]=2;arr[0][2]=3;
  26. arr[1][0]=4;arr[1][1]=5;arr[1][2]=6;
  27. arr[2][0]=7;arr[2][1]=8;arr[2][2]=9;
  28. func(arr,0,temp,ans);
  29. for(auto i:ans)
  30. {
  31. for(auto j:i)
  32. cout<<j<<" ";
  33. cout<<endl;
  34. }
  35. // your code goes here
  36. return 0;
  37. }
Success #stdin #stdout 0s 15248KB
stdin
Standard input is empty
stdout
1 4 7 
1 4 8 
1 4 9 
1 5 7 
1 5 8 
1 5 9 
1 6 7 
1 6 8 
1 6 9 
2 4 7 
2 4 8 
2 4 9 
2 5 7 
2 5 8 
2 5 9 
2 6 7 
2 6 8 
2 6 9 
3 4 7 
3 4 8 
3 4 9 
3 5 7 
3 5 8 
3 5 9 
3 6 7 
3 6 8 
3 6 9