Question

Chess horse walks - two cells vertically in any direction and one cell horizontally, or vice...

Chess horse walks - two cells vertically in any direction and one cell horizontally, or vice versa. Two different cells of the chessboard are given, determine whether the horse can get from the first cage to the second one move.
Input format
The program receives four numbers from 1 to 8 each, setting the column number and the number of the line first for the first cell, then for the second cell.
Output format
The program should withdraw YES if the first cage by the stroke of the horse can get into
the second or NO otherwise.

Homework Answers

Answer #1

Since this question doesnt specify a programming language I am using c++.

This question asks if a horse can reach from one cell to another in one move.

#include<bits/stdc++.h>
using namespace std;


int main()
{
   int x1,x2,y1,y2;
  
   cin>>x1>>y1>>x2>>y2;
  
   if(abs(x1-x2)==2&&(abs(y1-y2)==1))
       cout<<"YES"<<endl;
   else if(abs(x1-x2)==1&&abs(y1-y2)==2)
       cout<<"YES"<<endl;
   else
       cout<<"NO"<<endl;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions