Go to diff to previous submission
#include <stdio.h> #define SIZE 100 int R, C, Gr, Gc, Lr, Lc, board[SIZE*SIZE], j, s1, s2, i, r1, r2; int m[8][2] = {{-2, 1}, {-1, 2}, {1, 2}, {2, 1}, {2, -1}, {1, -2}, {-1, -2}, {-2, -1}}; int main() { for(i = 0; i < SIZE*SIZE; i++) { board[i] = 0; } board[(Gr-1)*R+Gc-1] = 1; j = 1; while (board[(Lr-1)*R+Lc-1] == 0 && j <= SIZE*SIZE) { for (s1 = 0; s1 < R; s1++) { for (s2 = 0; s2 < C; s2++) { if (board[s1*R+s2] == j) { for(i = 0; i < 8; i++) { r1 = s1+m[i][0]; r2 = s2+m[i][1]; if ((r1 >= 0 && r1 < R && r2 >= 0 && r2 < C) && board[r1*R+r2] == 0) { board[r1*R+r2] = j+1; } } } } } j++; } if (board[(Lr-1)*R+Lc-1] > 0) else } return 0; }