robot standing at first cell of an M*N matrix. It can move only in two directions, right and down. In how many ways, it can reach to the last cell i.e. (M, N) Code it

Robot standing at first cell of an M*N matrix. It can move only in two directions, right and down. In how many ways, it can reach to the last cell i.e. (M, N) Code it.

Thanks to Dhaval for suggesting this approach and Article

Method1 : 

We can go backword from (M,N) to (1,1)
As we can take only Up and Left Direction one step , from there we can take either M-1 or N-1

int NumberOfWaysMN(int m, int n)
{
if (m==1 || n ==1) return 1;
else {  return recursive(m-1, y) + recursive(x, n-1);  }

}//Function

Variant 2  For N*N : 

For an NxN square it takes (2N - 2) steps to move from the upper left corner to bottom right corner. 
Of these steps, half must be right and half must be down (N - 1 in each direction). 
Knowing this, we can look at it as a string permutation or how many ways can you write "RRRDDD", etc. 
(this would be for N = 4, "RRDD" for N = 3 and so on). 
Now we just have to count the number of permutations for this string which in terms of N will be (2N - 2)!/((N - 1)!(N - 1)!). 
These numbers match up....

2, 2 
3, 6 
4, 20 
5, 70 
6, 252 
7, 924 
8, 3432

-IF YOU LIKE OUR EFFORT, PLEASE LIKE AND SHARE OUR FB-PAGE AND SITE