NxNグリッドの左上隅にロボットが座っているとします。ロボットは右、下、斜め下の3方向にしか移動できません。ロボットは、NxNグリッドの右下に到達する必要があります。特定の四角形が「オフリミット」または「オフセット」であり、ロボットがその上に乗ることができないとします。ロボットに可能なパスの数を決定するプログラムを作成します。ここでNxNグリッド内のすべてのパスを見つける
が私のコードです:実行時に
#include<stdio.h>
#include<string.h>
int abc[50]={}, count=0;
int ak[5][5];
void called(int a,int b,int c){
if(a==c-1 && b==c-1){
int i=0;
printf("(0 , 0) - ");
for(i=0;i<count;i+=2){
if(i==count-2)
printf("(%d , %d)",abc[i],abc[i+1]);
else
printf("(%d , %d) - ",abc[i],abc[i+1]);
}
printf("\n");
abc[count--]=-1;
abc[count--]=-1;
return;
}
else{
if(a!=c-1 && ak[a][b]!=1){
abc[count++]=a+1;
abc[count++]=b;
called(a+1,b,c);
}
if(b!=c-1 && ak[a][b]!=1){
abc[count++]=a;
abc[count++]=b+1;
called(a,b+1,c);
}
if(a!=c-1 && a!=c-1 && ak[a][b]!=1){
abc[count++]=a+1;
abc[count++]=b+1;
called(a+1,b+1,c);
}
abc[count--]=-1;
abc[count--]=-1;
}
}
void main(){
int a,b,i,j,n;
printf("Enter the size of the grid\n");
scanf("%d",&n);
if(n>=0){
for(i=0;i<n;i++)
for(j=0;j<n;j++)
ak[i][j]=0;
printf("Enter the grid points that are offsets\n");
scanf("%d",&a);
scanf("%d",&b);
while(a!=-1 && b!=-1){
ak[a][b]=1;
scanf("%d",&a);
scanf("%d",&b);
}
printf("The paths for the robot are\n");
called(0,0,n);
}
else
printf("Invalid Input");
getchar();
}
、エラーが
Program terminated due to "Segmentation fault" (11)
コンパイル時にsegフォルトが発生する??? –
Eric Lippertによる[小さなプログラムのデバッグ方法](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)を読んで、*デバッガの使い方を学ぶことをお勧めします*あなたのプログラムでこのようなクラッシュをキャッチする。 –
[this](https://stackoverflow.com/q/45522468/971127)を参照してください。 – BLUEPIXY