#include <iostream> #include <string> #include <sstream> int n, m; int findWays(int x, int y, std::string str) { if (x <= n && y <= m) { str += "("; str += std::to_string(x); str += ", "; str += std::to_string(y); str +="), "; if (x == n && y == m) { std::cout << "Path End : " << str << std::endl; return 1; } int right = findWays(x + 1, y, str); int down = findWays(x, y + 1, str); return (right + down); } else { return 0; } } int main() { n = 3; m = 3; std::cout << "Paths :\n"; int count = findWays(1,1,""); std::cout << " Total no of Paths : " << count << std::endl; return 0; }
Standard input is empty
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