[In a hurry] I don't know why there's an infinite loop in finding n-queen using c language

Asked 2 years ago, Updated 2 years ago, 29 views

int is_safe(int i,int j) { int k = 1; int num = i;

i--;

while (i = !0)
{
    if (board[i][j] == 1) return 0;
    i--;
}

i = (num-1);

while (i = !0 && j+k <= size)
{
    if (board[i][j + k] == 1) return 0;
    k++;
    i--;
}

i = (num-1);
k = 1;

while (i = !0 && j-k >0)
{
    if (board[i][j - k] == 1) return 0;
    k++;
    i--;
}

return 1;

}

Finding n-Queen. I made it, but I can't debug it. 프로그래 I think the program keeps running<

c

2022-09-22 19:33

1 Answers

  while (I : zero!).

where !0 is 1 (! is NOT operator)

1 corresponds to True during True/False, and it is substituted for i.

It's a structure that goes around an infinite loop.

while(i!=0)

You can change it to~

!= operator means 'if not equal'.


2022-09-22 19:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.