Rat Chases its cheese

#include
using namespace std;

bool ratInMaze(char maze[10][10],int soln[10][10],int i,int j,int n,int m){

//To check for the starting and the ending index also
if(maze[i][j]=='X'){
    return false;
}

if(i==n&&j==m){
    soln[n][m]=1;

for(int i=0;i<=n;i++){
    for(int j=0;j<=m;j++){
        cout<<soln[i][j]<<" ";
    }
    cout<<endl;
}        

    return true;
}

if(i>n||j>m||i<0||j<0){
    return false;
}

bool right,down,up,left;
soln[i][j] = 1;

if(soln[i+1][j]==0){
    down = ratInMaze(maze,soln,i+1,j,n,m);
}
//Modiificatons:
if(soln[i][j+1]==0 && !down){
    right = ratInMaze(maze,soln,i,j+1,n,m);
}
if(soln[i-1][j]==0 && !down && !right){
    up = ratInMaze(maze,soln,i-1,j,n,m);
}
if(soln[i][j-1]==0 && !down && !right && !up){
    left = ratInMaze(maze,soln,i,j-1,n,m);
}

if(right||down||left||up){
    return true;
}
//Modification:
soln[i][j] = 0;

return false;

}

int main() {
int n,m;
cin>>n>>m;

char maze[10][10];

for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
        cin>>maze[i][j];
    }
}

int soln[10][10]={0};

bool ans = ratInMaze(maze,soln,0,0,n-1,m-1);

if(ans==false){
    cout<<"NO PATH FOUND";
}

return 0;

}

Please tell what is wrong in this code and please correct it if possible

hello @yajurkhurana

pls go to this link -> https://ide.codingblocks.com/
paste ur code , press ctrl + s and then save

a url will be generated in ur search bar , share that url with me

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.