fork(1) download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3.  
  4. void flipslash(char *slash);
  5. void flipspacer(int *front_spacer, int *back_spacer);
  6. void printline(char *slash, int diamond_size, int front_spacer, int back_spacer);
  7.  
  8. int main() {
  9. char slash = '/';
  10. int total, rows, columns, diamond_size, front_spacer, back_spacer;
  11. scanf("%i", &total);
  12.  
  13.  
  14. //total reps
  15. for (int reps = 0; reps < total; reps++) {
  16. //fill values
  17. scanf("%i%i%i", &rows, &columns, &diamond_size);
  18.  
  19. for (int line = 0; line < rows; line++) {
  20. //top half of diamond
  21. for (int j = 0; j < diamond_size; j++) {
  22. front_spacer = diamond_size - 1 - j;
  23. back_spacer = j;
  24. for (int i = 0; i < columns; i++) {
  25. printline(&slash, diamond_size, front_spacer, back_spacer);
  26. }
  27. printf("\n");
  28. }
  29. flipslash(&slash);
  30. //lower half of diamond
  31. for (int j = 0; j < diamond_size; j++) {
  32. front_spacer = j;
  33. back_spacer = diamond_size - 1 - j;
  34. for (int i = 0; i < columns; i++) {
  35. printline(&slash, diamond_size, front_spacer, back_spacer);
  36. }
  37. printf("\n");
  38. }
  39. flipslash(&slash);
  40. }
  41. printf("\n");
  42. }
  43. return 0;
  44. }
  45.  
  46. void flipslash(char *slash) {
  47. if (*slash == '/') *slash = '\\';
  48. else *slash = '/';
  49. }
  50.  
  51. void flipspacer(int *front_spacer, int *back_spacer) {
  52. int temp = *front_spacer;
  53. *front_spacer = *back_spacer;
  54. *back_spacer = temp;
  55. }
  56.  
  57. void printline(char *slash, int diamond_size, int front_spacer, int back_spacer) {
  58. int temp, odd_or_even, times_run;
  59. odd_or_even = diamond_size % 2;
  60. if (odd_or_even) times_run = diamond_size + 1;
  61. else times_run = diamond_size;
  62. for (int i = 0; i < times_run; i++) {
  63. //print front_spacer
  64. for (int j = 0; j < front_spacer; j++) {
  65. printf(".");
  66. }
  67. printf("%c", *slash);
  68. //print back_spacer
  69. for (int j = 0; j < back_spacer; j++) {
  70. printf(".");
  71. }
  72. flipslash(&*slash);
  73. temp = front_spacer;
  74. front_spacer = back_spacer;
  75. back_spacer = temp;
  76. }
  77. }
  78.  
Success #stdin #stdout 0s 9424KB
stdin
3
3 1 2
4 4 1
2 5 2
stdout
./\.
/..\
\../
.\/.
./\.
/..\
\../
.\/.
./\.
/..\
\../
.\/.

/\/\/\/\
\/\/\/\/
/\/\/\/\
\/\/\/\/
/\/\/\/\
\/\/\/\/
/\/\/\/\
\/\/\/\/

./\../\../\../\../\.
/..\/..\/..\/..\/..\
\../\../\../\../\../
.\/..\/..\/..\/..\/.
./\../\../\../\../\.
/..\/..\/..\/..\/..\
\../\../\../\../\../
.\/..\/..\/..\/..\/.