/* User input : X and Y positions of Knight
Out Put : 2 steps
*/
# include <stdio.h>
# include <conio.h>
/* possible moves total 8 moves can be possible*/
int xMove[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int yMove[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };
int prop_count(int x,int y)
{
int mcount=0;
int s;
printf("\nKnight Positions are\n");
for(s=0;s<=7;s++)
{
if( x+xMove[s]>=0 && x+xMove[s]<=7)
if( y+yMove[s]>=0 && y+yMove[s]<=7)
{
printf("\n%d,%d",x+xMove[s],y+yMove[s]);
mcount++;
}
}
return mcount;
}
main(){
int board[8][8];
int x,y;
clrscr();
printf("\nboard [0,0 is start and 7,7 is end]\nEnter X and Y position of?");
scanf("%d%d",&x,&y);
printf("\nTotal count of Moves : %d",prop_count(x,y));
}
Out Put : 2 steps
*/
# include <stdio.h>
# include <conio.h>
/* possible moves total 8 moves can be possible*/
int xMove[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int yMove[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };
int prop_count(int x,int y)
{
int mcount=0;
int s;
printf("\nKnight Positions are\n");
for(s=0;s<=7;s++)
{
if( x+xMove[s]>=0 && x+xMove[s]<=7)
if( y+yMove[s]>=0 && y+yMove[s]<=7)
{
printf("\n%d,%d",x+xMove[s],y+yMove[s]);
mcount++;
}
}
return mcount;
}
main(){
int board[8][8];
int x,y;
clrscr();
printf("\nboard [0,0 is start and 7,7 is end]\nEnter X and Y position of?");
scanf("%d%d",&x,&y);
printf("\nTotal count of Moves : %d",prop_count(x,y));
}
No comments:
Post a Comment