shifting in a 2d array

Write a program for the following puzzle:
Very often in fairs we come across a puzzle which contains numbered square pieces, which can be
moved horizontally or vertically. A possible arrangement of these pieces is shown below (Hint: This is a
2D integer array!):
1 4 15 7
8 10 2 11
14 3 6 13
12 9 5 ☺
As you can see there is a ☺ at bottom right corner. Implement the program so that a box like the above
one is displayed (lines may not be displayed). Allow the user to hit any of the arrow keys (up, down, left,
or right).
If user hits say, right arrow key then program should give a message that this movement is not possible.
If user hits left arrow key then 5 should move in place of ☺ and ☺ should move in place of 5, and box
will look like:
1 4 15 7
8 10 2 11
14 3 6 13
12 9 ☺ 5
Similarly, you can experience with all arrow keys and movements of ☺ will take place, if possible. The
user would continue hitting the arrow keys till the numbers aren’t sorted in ascending order.
Interesting idea for a program.
Thank you.

int main
This can be done it two simple steps:

1.) Do it
2.) You are done!
Topic archived. No new replies allowed.