fork download
  1. #include <stdio.h>
  2.  
  3. #define WIDTH 11
  4. #define HEIGHT 11
  5.  
  6. char grid[HEIGHT][WIDTH];
  7.  
  8. // Function to initialize the grid with dots
  9. void initGrid() {
  10. for (int y = 0; y < HEIGHT; y++)
  11. for (int x = 0; x < WIDTH; x++)
  12. grid[y][x] = '.';
  13. }
  14.  
  15. // Function to print the grid with origin at center
  16. void printGrid() {
  17. for (int y = HEIGHT - 1; y >= 0; y--) {
  18. for (int x = 0; x < WIDTH; x++) {
  19. printf("%c ", grid[y][x]);
  20. }
  21. printf("\n");
  22. }
  23. }
  24.  
  25. // Converts coordinate (x, y) to grid position
  26. void plotPoint(int x, int y, char symbol) {
  27. int gridX = x + WIDTH / 2;
  28. int gridY = y + HEIGHT / 2;
  29.  
  30. if (gridX >= 0 && gridX < WIDTH && gridY >= 0 && gridY < HEIGHT)
  31. grid[gridY][gridX] = symbol;
  32. }
  33.  
  34. int main() {
  35. initGrid();
  36.  
  37. // Original triangle ABC
  38. int Ax = 2, Ay = 2;
  39. int Bx = 6, By = 2;
  40. int Cx = 4, Cy = 5;
  41.  
  42. // Plot original triangle points
  43. plotPoint(Ax, Ay, 'A');
  44. plotPoint(Bx, By, 'B');
  45. plotPoint(Cx, Cy, 'C');
  46.  
  47. // Reflected triangle A'B'C' across X-axis (negate Y)
  48. plotPoint(Ax, -Ay, 'a');
  49. plotPoint(Bx, -By, 'b');
  50. plotPoint(Cx, -Cy, 'c');
  51.  
  52. printf("Grid showing Triangle ABC and its reflection (a, b, c) across X-axis:\n\n");
  53. printGrid();
  54.  
  55. return 0;
  56. }
  57.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Grid showing Triangle ABC and its reflection (a, b, c) across X-axis:

. . . . . . . . . C . 
. . . . . . . . . . . 
. . . . . . . . . . . 
. . . . . . . A . . . 
. . . . . . . . . . . 
. . . . . . . . . . . 
. . . . . . . . . . . 
. . . . . . . a . . . 
. . . . . . . . . . . 
. . . . . . . . . . . 
. . . . . . . . . c .