fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4.  
  5. int n, m;
  6.  
  7. int findWays(int x, int y, std::string str)
  8. {
  9. if (x <= n && y <= m)
  10. {
  11. str += "(";
  12. str += std::to_string(x);
  13. str += ", ";
  14. str += std::to_string(y);
  15. str +="), ";
  16. if (x == n && y == m)
  17. {
  18. std::cout << "Path End : " << str << std::endl;
  19. return 1;
  20. }
  21. int right = findWays(x + 1, y, str);
  22. int down = findWays(x, y + 1, str);
  23. return (right + down);
  24. }
  25. else
  26. {
  27. return 0;
  28. }
  29. }
  30.  
  31. int main()
  32. {
  33. n = 3;
  34. m = 3;
  35. std::cout << "Paths :\n";
  36. int count = findWays(1,1,"");
  37. std::cout << " Total no of Paths : " << count << std::endl;
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
Paths :
Path End : (1, 1), (2, 1), (3, 1), (3, 2), (3, 3), 
Path End : (1, 1), (2, 1), (2, 2), (3, 2), (3, 3), 
Path End : (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), 
Path End : (1, 1), (1, 2), (2, 2), (3, 2), (3, 3), 
Path End : (1, 1), (1, 2), (2, 2), (2, 3), (3, 3), 
Path End : (1, 1), (1, 2), (1, 3), (2, 3), (3, 3), 
 Total no of Paths : 6