// ChessKingQueen.c : Questo file contiene la funzione 'main', in cui inizia e termina l'esecuzione del programma. // #include #include #include int xK, yK, xQ, yQ; int main() { printf("This program indicates, given the position of the king and queen on a chessboard,\nwhether the queen can eat the king.\n\n"); printf("Enter the king column (1-8): "); if (scanf("%d", &xK) != 1) { perror("Error reading king column: \n"); exit(1); } printf("Enter the king row (1-8): "); if (scanf("%d", &yK) != 1) { perror("Error reading king row: \n"); exit(1); } printf("Enter the queen column (1-8): "); if (scanf("%d", &xQ) != 1) { perror("Error reading queen column: \n"); exit(1); } printf("Enter the queen row (1-8): "); if (scanf("%d", &yQ) != 1) { perror("Error reading queen row: \n"); exit(1); } if ( (xK == xQ) || (yK == yQ) || ((yK - yQ)/(xK - xQ) == 1) || ((yK - yQ)/(xK - xQ) == -1)) { printf("The queen eats the king"); } else { printf("The queen does not eat the king"); } return 0; }