424,994 Members | 2,073 Online
Need help? Post your question and get tips & solutions from a community of 424,994 IT Pros & Developers. It's quick & easy.

# A Maze problem in C++ using recursion

 P: 1 I have a C++ problem that i just can not get right. I has been driving me crazy for quite some time. The problem is as follows : Numbers have been randomly inputed into an integer 2D array by the user. The program has to find a path from the top left corner to the bottom right corner but also keeping in mind to find the path/s whose sum is minimum. Only up and down and sideways movement is allowed.Diagonal movement is not allowed. I have already written a code but it just hangs or goes into an infinite recursions.The code I have used is : int pathSum(int a[MAX][MAX],int r,int c, int row,int col,int sum) {int ci,ri; static int min=0; for(ri=-1;ri<=1;ri++) {if(r+ri<0||r+ri>=row) continue; for(ci=-1;ci<=1;ci++) {if(c+ci<0||c+ci>=col||(ci+ri)%2==0) continue; if(r!=row||c!=col) {sum+=a[r][c]; pathSum(a, r+ri,c+ci,row,col,sum); } else {if(sum