Recursion Lab Assignment This lab will use 2D arrays recursi
Solution
Maze Traversal - First of all we outline our program and then w write the required code for it.
Outline of the program
 First of all we will declare functions that will be required to traverse the maze, check for the right move, check for the surrounding environment(edges) and the display of the maze.
 Then we will store the maze in an array
 And last of all we will determine a way out of the maze by using our functions.
// Code to find the exit//
#include <studio.h>
 #include <stdlib.h>
#define XSTART 2
 #define YSTART 0
// We wil define each direction with the help of an integer value so that we can use them to decide a move//
#define DOWN 0
 #define RIGHT 1
 #define UP 2
 #define LEFT 3
void mazeTraverse(char maze[12][12], int xCor, int yCor, int dir);
 int checkForEdge(int x, int y)
 int correctMove(char maze[][12], int r, int c);
 void displayMaze(char maze[][12]);
int main(void)
 {
 char maze[12][12] = {
            {\'#\',\'#\',\'#\',\'#\',\'#\',\'#\',\'#\',\'#\',\'#\',\'#\',\'#\',\'#\'},
            {\'#\',\'-\',\'-\',\'-\',\'#\',\'-\',\'-\',\'-\',\'-\',\'-\',\'-\',\'#\'},
            {\'-\',\'-\',\'#\',\'-\',\'#\',\'-\',\'#\',\'#\',\'#\',\'#\',\'-\',\'#\'},
            {\'#\',\'#\',\'#\',\'-\',\'#\',\'-\',\'-\',\'-\',\'-\',\'#\',\'-\',\'#\'},
            {\'#\',\'-\',\'-\',\'-\',\'-\',\'#\',\'#\',\'#\',\'-\',\'#\',\'-\',\'#\'},
            {\'#\',\'#\',\'#\',\'#\',\'-\',\'#\',\'-\',\'#\',\'-\',\'#\',\'-\',\'#\'},
            {\'#\',\'-\',\'-\',\'#\',\'-\',\'#\',\'-\',\'#\',\'-\',\'#\',\'-\',\'#\'},
            {\'#\',\'#\',\'-\',\'#\',\'-\',\'#\',\'-\',\'#\',\'-\',\'#\',\'-\',\'#\'},
            {\'#\',\'-\',\'-\',\'-\',\'-\',\'-\',\'-\',\'-\',\'-\',\'#\',\'-\',\'#\'},
            {\'#\',\'#\',\'#\',\'#\',\'#\',\'#\',\'-\',\'#\',\'#\',\'#\',\'-\',\'#\'},
            {\'#\',\'-\',\'-\',\'-\',\'-\',\'-\',\'-\',\'#\',\'-\',\'-\',\'-\',\'#\'},
            {\'#\',\'#\',\'#\',\'#\',\'#\',\'#\',\'#\',\'#\',\'#\',\'#\',\'#\',\'#\'};
               
       
 //Call the mazeTraverse function//
 mazeTraverse(maze, XSTART, YSTART, RIGHT);
 return 0;
 }
void mazeTraverse (char maze[12][12], int xCor, int yCOr, int dir)
 {
 static int flag = 0;
 maze[xCor][yCor] = \'X\";
 displayMaze (maze);
//Check if maze is complete//
 if(checkForEdge (xCor, yCOr) && xCor !- XSTART && yCor !=YSTART)
 {
 printf(\"Successfully exit the maze\");
 return;
 }
elseif (xCor == XSTART && yCor == YSTART && flag == 1)
 {
 printf(\"You are back to the starting position\");
 return;
 }
 else
 {
     int counter;
    int nextMove;
    flag = 1;
   
    for (nextMove = dir, counter = 0; counter < 4; ++counter, ++nextMove,    nextMove == 4)
        {
            switch(nextMove)
                {
                case DOWN:
                if(correctMove(maze, xCor + 1, yCor, LEFT);
                return;
                }
                break;
               case RIGHT:
                if(correctMove(maze, xCor, yCor + 1, DOWN);
                return;
                }
                break;
               
                case UP
                if(correctMove(maze, xCor - 1, yCor, RIGHT);
                return;
                }
                break;
               case LEFT
                if(correctMove(maze, xCor, yCor - 1, UP);
                return;
                }
                break;
                }
            }
    }
 }
int correctMove(char maze[][12], int r, int c)
 {
    return (r>=0 && r<= 11 && c>= 0 && c<= 11 && maze [r][c] != \'#\');
 }
 int checkForEdge(int x, int y)
 {
    if ((x = 0 || x ==11) && (y>= 0 && y<= 11))
    {
        return 1;
    }
    else if (( y == 0 || y == 11) && (x >= 0 && x<= 11))
    {
    return 1;
    }
    else
    {
    return 0;
    }
 }
 void displayMaze (char maze [][12])
 {
    int x;
    int y;
    for (x=0; x < 12; x++)
    {
        for (y =0; y <12; y++)
        {
            printf(\"%c\", maze [x][y]);
        }
    printf(\"\ \");
    }
 printf(\"\ Hit enter to go to the next move\");
 getchar();
 }



