#include #define ROWS 5 #define COLS 5 int main () { int n, r, c, space = ROWS*COLS - 1; int grid[ROWS*COLS]; char move; for ( n = 0; n < ROWS*COLS; ++n ) grid[n] = ROWS*COLS - 1 - n; do { for ( r = 0; r < ROWS; ++r ) { for ( c = 0; c < COLS; ++c ) if ( grid[r * COLS + c] == 0 ) printf(" "); else printf("%3d", grid[r * COLS + c]); printf("\n"); } printf("Enter Space Movement (U: Up, D: Down, R: Right, L: Left, E: Exit): "); scanf(" %c", &move); switch(move) { case 'U': case 'u': if ( space - COLS >= 0 ) { grid[space] = grid[space - COLS]; grid[space - COLS] = 0; space = space - COLS; } break; case 'D': case 'd': if ( space + COLS < ROWS*COLS ) { grid[space] = grid[space + COLS]; grid[space + COLS] = 0; space = space + COLS; } break; case 'R': case 'r': if ( (space+1)%COLS != 0 ) { grid[space] = grid[space + 1]; grid[space + 1] = 0; space = space + 1; } break; case 'L': case 'l': if ( space%COLS != 0 ) { grid[space] = grid[space - 1]; grid[space - 1] = 0; space = space - 1; } break; case 'E': case 'e': break; default: printf("-- Choice NOT Listed --\n"); break; } } while ( (move != 'E') && (move != 'e') ); return 0; }