#include <stdio.h>

void knight(int x, int y, int count)
{
	int i, j;
	static int step[8][2] = {{2, 1}, {1, 2}, {-1, 2}, {-2, 1}, {-2, -1}, {-1, -2}, {1, -2}, {2, -1}};
	static int board[12][12] = {
		{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
		{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
		{ -1, -1,  0,  0,  0,  0,  0,  0,  0,  0, -1, -1},
		{ -1, -1,  0,  0,  0,  0,  0,  0,  0,  0, -1, -1},
		{ -1, -1,  0,  0,  0,  0,  0,  0,  0,  0, -1, -1},
		{ -1, -1,  0,  0,  0,  0,  0,  0,  0,  0, -1, -1},
		{ -1, -1,  0,  0,  0,  0,  0,  0,  0,  0, -1, -1},
		{ -1, -1,  0,  0,  0,  0,  0,  0,  0,  0, -1, -1},
		{ -1, -1,  0,  0,  0,  0,  0,  0,  0,  0, -1, -1},
		{ -1, -1,  0,  0,  0,  0,  0,  0,  0,  0, -1, -1},
		{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
		{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}};

	board[x][y] = count;
	if(count == 64){
		printf("-----\n");
		for(i = 2; i < 10; i++)
		{
			for(j = 2; j < 10; j++)
				printf("%3d", board[i][j]);
			printf("\n");
		}
exit(0);
	}else{
		for(i = 0; i < 8; i++)
		{
			if(board[x + step[i][0]][y + step[i][1]] == 0)
				knight(x + step[i][0], y + step[i][1], count + 1);
		}
	}
	board[x][y] = 0;
}

main()
{
	knight( 2, 2, 1);
}

