Mazewalk and find the total number of path available

This program will give the output total number of paths available in mXn maze frame. This will be useful in finding the shortest distance between cells.

Complete C++ program is given below:

#include <iostream.h>
#include<conio.h>
long countPaths;

void findPath(int row, int col)
{
    int next_pos[3][2];
    int i;
    int paths = 0;
    int found = 0;
    
    if(row == 3 && col == 3)
    {
        countPaths++;
        return;
    }

    next_pos[0][0] = row+1;        next_pos[0][1] = col;
    next_pos[1][0] = row;        next_pos[1][1] = col+1;
    next_pos[2][0] = row+1;        next_pos[2][1] = col+1;

    for(i=0; i<3; i++)
    {
        if(next_pos[i][0] < 4 && next_pos[i][1] < 4) {
            printf("(%d,%d)",next_pos[i][0],next_pos[i][1]);
            findPath(next_pos[i][0],next_pos[i][1]);
        }
    }
    return;
}
int main()
{
    findPath(0,0);
    cout<<"total paths available "<<countPaths<<"\n";
    getch();
}

Regards,
Megha
By Perry    Popularity  (552 Views)