tannebaumv3.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <stdio.h>
  2. #define GRID_SIZE 9
  3. #define GRID_MIDDLE GRID_SIZE/2
  4. void initGrid(char grid[][GRID_SIZE]);
  5. void printGrid(char grid[][GRID_SIZE]);
  6. void makeTree(char grid[][GRID_SIZE]);
  7. int main(void) {
  8. char grid[GRID_SIZE][GRID_SIZE];
  9. char symbol = '*';
  10. initGrid(grid);
  11. makeTree(grid);
  12. printGrid(grid);
  13. return 0;
  14. }
  15. void initGrid(char grid[][GRID_SIZE]) {
  16. for (int x = 0; x < GRID_SIZE; x++)
  17. for (int y = 0; y < GRID_SIZE; y++)
  18. grid[x][y] = ' ';
  19. // or memset(grid, ' ', GRID_SIZE * GRID_SIZE);
  20. }
  21. void printGrid(char grid[][GRID_SIZE]) {
  22. for (int x = 0; x < GRID_SIZE; x++) {
  23. for (int y = 0; y < GRID_SIZE; y++)
  24. printf("[%c]", grid[x][y]);
  25. printf("\n");
  26. }
  27. }
  28. void makeTree(char grid[][GRID_SIZE]) {
  29. for (int x = 0; x < GRID_SIZE; x++ ) {
  30. for (int y = 0; y < GRID_SIZE; y++) {
  31. grid[x][y] = ' ';
  32. }
  33. for (int y = 0; y < x/2; y++) {
  34. grid[y][x] = '^';
  35. grid[x][y] = '*';
  36. }
  37. }
  38. }