Count all possible paths from top left to bottom right of a mXn matrix in C++

C++Server Side ProgrammingProgramming

<p>In this tutorial, we will be discussing a program to find the number of possible paths from top left to bottom right of a mXn matrix.</p><p>For this we will be provided with a mXn matrix. Our task is to find all the possible paths from top left to bottom right of the given matrix.</p><h2>Example</h2><pre class="prettyprint notranslate">#include &lt;iostream&gt; using namespace std; //returning count of possible paths int count_paths(int m, int n){ &nbsp; &nbsp;if (m == 1 || n == 1) &nbsp; &nbsp; &nbsp; return 1; &nbsp; &nbsp;return count_paths(m - 1, n) + count_paths(m, n - 1); } int main(){ &nbsp; &nbsp;cout &lt;&lt; count_paths(3, 3); &nbsp; &nbsp;return 0; }</pre><h2>Output</h2><pre class="result notranslate">6</pre>
raja
Updated on 10-Feb-2020 12:08:04

Advertisements