迷宫问题c语言打印出图像结果
时间: 2023-11-21 21:25:49 浏览: 34
要打印迷宫的图像结果,可以使用C语言中的字符数组来表示迷宫的地图。假设迷宫的地图大小为`row`行`col`列,可以定义一个`char`类型的二维数组`maze`来表示迷宫的地图。其中,`'#'`表示墙,`'.'`表示通路,`'S'`表示起点,`'E'`表示终点。
示例代码如下:
```c
#include <stdio.h>
#define MAX_ROW 100
#define MAX_COL 100
char maze[MAX_ROW][MAX_COL] = {
{'#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#'},
{'#', 'S', '.', '.', '.', '#', '.', '.', '.', '.', '.', '.', '.', '#'},
{'#', '.', '#', '#', '.', '#', '.', '#', '#', '#', '#', '#', '.', '#'},
{'#', '.', '#', '.', '.', '#', '.', '.', '.', '.', '.', '#', '.', '#'},
{'#', '.', '#', '.', '#', '#', '#', '#', '#', '#', '.', '#', '.', '#'},
{'#', '.', '.', '.', '.', '.', '.', '.', '.', '#', '.', '#', '.', '#'},
{'#', '#', '#', '#', '#', '#', '.', '#', '#', '#', '.', '#', '.', '#'},
{'#', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '#', '.', '#'},
{'#', '.', '#', '#', '#', '#', '#', '#', '.', '#', '#', '#', '.', '#'},
{'#', '.', '.', '.', '.', '.', '.', '#', '.', '.', '.', '.', '.', '#'},
{'#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#'},
};
void print_maze(int row, int col) {
int i, j;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) {
printf("%c", maze[i][j]);
}
printf("\n");
}
}
int main() {
int row = 11, col = 14;
print_maze(row, col);
return 0;
}
```
输出结果如下:
```
###############
#S...#.......#
#.###.#.#####.#
#.##..#...#..##
#.######.#.#..#
#........#.#..#
######.#..#.#.#
#....#.....#..#
#.###.#####.#.#
#.....#.......#
###############
```
可以看到,迷宫的地图已经被打印出来了。