Count the number of ways to traverse a Matrix | Find factorial ; Find number of ways to reach mat [ m - 1 ] [ n - 1 ] from mat [ 0 ] [ 0 ] in a matrix mat [ ] [ ] ] ; Driver code ; Function Call
function factorial ( n ) { var res = 1 , i ; for ( i = 2 ; i <= n ; i ++ ) res *= i ; return res ; } function countWays ( m , n ) { m = m - 1 ; n = n - 1 ; return factorial ( m + n ) / ( factorial ( m ) * factorial ( n ) ) ; } var m = 5 ; var n = 5 ; var result = countWays ( m , n ) ; document . write ( result ) ;