Check if there is a path in an 8x8 matrix starting in the upper left corner, and ending in the lower right corner
How can i make this condition to this code in cpp?
We have to use the return search
Check if there is a path in an 8x8 matrix starting in the upper left corner, and ending in the lower right corner
#include <iostream>
using namespace std;
#define maxN 20
char m[maxN][maxN];
int n;
bool way = false;
void init(){
int i, j;
do{
cout << "n= ";
cin >> n;
}
while(n<1||n>20);
do{
cout << ":"<<endl;
for (i=0; i<=n-1; i++)
for (j=0; j<=n-1; j++)
cin >> m[i][j];
}
while(m[0][0]!='0');
}
void writelab(){
int k, l;
cout << endl;
for (k=0; k<=n-1; k++){
for (l=0; l<=n-1; l++)
cout << m[k][l] << " ";
cout << endl;
}
}
void Path(int i, int j){
if (i==n-1 && j==n-1){
m[i][j]='*';
way = true;
writelab();
}
else
if (i>=0 && i<=n-1 && j>=0 && j<=n-1)
if(m[i][j] == '0'){
m[i][j]='*';
Path(i+1,j);
Path(i,j+1);
Path(i-1,j);
Path(i,j-1);
m[i][j] = '0';
}
}
int main()
{
init();
Path(0,0);
if(!way) cout << "Nо path";
return 0;
}
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)