Skip to content

Commit

Permalink
Merge pull request #48 from cuttty/main
Browse files Browse the repository at this point in the history
added
  • Loading branch information
lordoz234 authored Nov 5, 2023
2 parents 6968167 + c3444df commit 832902a
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions task4/FrolovaS.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int ppp(int n, int m, int **a){
if (n<0 || m<0||n>=15 || m>=15){
return 0;
}
if (a[n][m]==2){
return 0;
}
if (a[n][m]==0){
return 0;
}
if (n==14 && m==14){
return 1;
}
if (a[n][m]==1){
a[n][m]=2;
return ppp(n+1, m, a) || ppp(n, m+1, a) || ppp(n-1, m, a) || ppp(n, m-1, a);
}

}

int main (){
srand(time(NULL));
int n=15, m=15,i,j,res;
scanf ("%d %d", &n, &m);
int **a = malloc(n*sizeof(int*));
for (i=0; i<n; i++){
a[i]=malloc(m*sizeof(int));}
for (i=0; i<n; i++){
for (j=0; j<m; j++){
int x;
x= 1+rand()%10;
if (x<2){
a[i][j]=0;
}
else {
a[i][j]=1;
}
}
}
a[0][0]=1;
a[14][14]=1;
res=ppp(0,0,a);
for (i=0; i<n; i++){
for (j=0; j<m; j++){
printf("%d ", a[i][j]);
}
printf("\n");

}
if (res==0) {
printf ("no ways");
}
else {
printf ("there is a way");
}
return 0;
}



0 comments on commit 832902a

Please sign in to comment.