123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #include <stdio.h>
-
- #define GRID_SIZE 9
- #define GRID_MIDDLE GRID_SIZE/2
-
- void initGrid(char grid[][GRID_SIZE]);
- void printGrid(char grid[][GRID_SIZE]);
- void makeTree(char grid[][GRID_SIZE]);
-
- int main(void) {
- char grid[GRID_SIZE][GRID_SIZE];
- char symbol = '*';
-
- initGrid(grid);
- makeTree(grid);
- printGrid(grid);
-
- return 0;
- }
-
- void initGrid(char grid[][GRID_SIZE]) {
- for (int x = 0; x < GRID_SIZE; x++)
- for (int y = 0; y < GRID_SIZE; y++)
- grid[x][y] = ' ';
- // or memset(grid, ' ', GRID_SIZE * GRID_SIZE);
- }
-
- void printGrid(char grid[][GRID_SIZE]) {
- for (int x = 0; x < GRID_SIZE; x++) {
- for (int y = 0; y < GRID_SIZE; y++)
- printf("[%c]", grid[x][y]);
- printf("\n");
- }
- }
- void makeTree(char grid[][GRID_SIZE]) {
- for (int x = 0; x < GRID_SIZE; x++ ) {
- for (int y = 0; y < GRID_SIZE; y++) {
- grid[x][y] = ' ';
- }
- for (int y = 0; y < x/2; y++) {
- grid[y][x] = '^';
- grid[x][y] = '*';
- }
- }
- }
|