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

C++Server Side ProgrammingProgramming

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.

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.

Example

#include <iostream>
using namespace std;
//returning count of possible paths
int count_paths(int m, int n){
   if (m == 1 || n == 1)
      return 1;
   return count_paths(m - 1, n) + count_paths(m, n - 1);
}
int main(){
   cout << count_paths(3, 3);
   return 0;
}

Output

6
raja
Published on 10-Feb-2020 16:37:38
Advertisements