I can only give you algorithm but it is very easy to convert it to code

I hope you know how to calculate the number of ways for your example the numbers of ways is 2 it can be calculate easily using another matrix ( Let us denote WM) to store number of way to reach aparticular block so

for

0 0 0

0 1 0

0 0 0

WM will be

1 1 1

1 0 1

1 1 2

( if you have doubt in how i calculated above WM , Comment… I will explain )

Now you have WM and it is known that we MUST start from upper leftmost block

in order to generate all the ways

u can use following pseudo code ( it uses stack )…

```
def print_path(present block , stack , direction)
if present block has zero :
return
if present block is destination:
print all the entries in stack and the direction also
else
decrease one in present block
push the direction in stack
print_path(present block to right , stack , right);
print_path(present block to down , stack , down);
return;
```

after writing the algo i came to know that we can go up and left also I Only did for right down may be you can extend this to that also , you take care of the limiting conditions like end of matrix etc…