How can i only print the rightmost path

#include
using namespace std;
bool ratinmaze(char grid[][20], int n, int m,int sol[][20], int i, int j ){
if( i == n && j == m){
sol[i][j] = 1;

	for( int i = 0; i<= n; i++){
		for( int j = 0; j<=m; j++){
			cout << sol[i][j] << " ";
		}
		cout << endl;
	}
	return true;
}
if( i > m || j > n){
	return false;
}
if( grid[i][j] == 'X'){
	return false;
}
sol[i][j] = 1;
 bool rightsuccess = ratinmaze(grid,m,n,sol,i,j+1);
 bool downsuccess = ratinmaze(grid,m,n,sol,i+1,j);
	
        sol[i][j] =0;

 return true;

}

int main() {
int n, m;
cin >> n>>m;
char grid[20][20];
for( int i = 0; i < n; i++){
for( int j = 0; j < m; j++){
cin >> grid[i][j];
}
}
int sol[20][20] ={0};
ratinmaze(grid,m-1,n-1,sol,0,0);
return 0;
}

check after this call whether rightSuccess is true or not
it it is true that means you have printed the right path so just return true
else call the down path

like this

bool rightsuccess = ratinmaze(grid,m,n,sol,i,j+1);
if(rightsuccess)
   return true;
 bool downsuccess = ratinmaze(grid,m,n,sol,i+1,j);

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.