1. #include <stdio.h>
  2.  
  3. void main()
  4.  
  5. {
  6.  
  7. // Incremental counting variables, used for counters for loops
  8. int i, j, x;
  9.  
  10. // Regular variables to determine tree size, amount of spaces and total spaces
  11. int tree_Size, spaces, total_Spaces;
  12.  
  13. // Character variables for each characer inputted by the user
  14. char tree_Characters, tree_Top, tree_Trunk, tree_Base, tree_Middle, null_Terminator;
  15.  
  16. printf("Enter characters to use --> ");
  17.  
  18. scanf("%c", &tree_Top);
  19.  
  20. // Determine whether the first character holds any data
  21. if (tree_Top == '\n') {
  22. printf("Fail, tree_Top is null\n");
  23. return;
  24. }
  25. else if (tree_Top != '\n')
  26. scanf("%c", &tree_Trunk);
  27.  
  28. // Determine whether the second character holds any data
  29. if (tree_Trunk == '\n') {
  30. printf("Fail, tree_Trunk is null\n");
  31. return;
  32. }
  33. else if (tree_Trunk != '\n')
  34. scanf("%c", &tree_Base);
  35.  
  36. // Determine whether the third character holds any data
  37. if (tree_Base == '\n') {
  38. printf("Fail, tree_Base is null\n");
  39. return;
  40. }
  41. else if (tree_Base != '\n')
  42. scanf("%c", &tree_Middle);
  43.  
  44. // Determine whether the fourth character holds any data
  45. if (tree_Middle == '\n') {
  46. printf("Fail, tree_Middle is null\n");
  47. return;
  48. }
  49. else if (tree_Middle != '\n')
  50. scanf("%c", &null_Terminator);
  51.  
  52. /* Determine whether the fifth character holds any data, if it does, display
  53.   an error message and terminate the program */
  54. if (null_Terminator != '\n') {
  55. printf("Fail, null_Terminator is NOT null\n");
  56. return;
  57. }
  58. // If it does not hold data, continue with program execution
  59. else if (null_Terminator == '\n') {
  60. printf("Enter size of tree --> ");
  61. scanf("%d", &tree_Size);
  62. // Check if size of tree does not exceed 20 or fall below 1
  63. if (tree_Size < 1 || tree_Size > 20) {
  64. printf("\n");
  65. printf("ERROR: Must enter a tree size between 1 and 20!");
  66. }
  67. else
  68. {
  69. //For handling top part of tree
  70. for (i = 0; i <= tree_Size; i++) {
  71. printf("\n");
  72. total_Spaces = tree_Size - i;
  73.  
  74. //Determine spaces before each number for pyramid
  75. for (spaces = 1; spaces <= total_Spaces; spaces++)
  76. printf(" ");
  77.  
  78. //Make first line always one number
  79. for (j = -1; j < i; j++)
  80. if (j <= -1)
  81. printf("%c", tree_Top);
  82. else if (j > -1)
  83. printf("%c%c", tree_Top, tree_Top);
  84. }
  85.  
  86. //For handling stem and base of tree
  87. for (i = 0; i <= tree_Size; i++) {
  88.  
  89. //if handling stem
  90. if (i < tree_Size) {
  91. printf("\n");
  92. for (spaces = 1; spaces <= tree_Size; spaces++)
  93. printf(" ");
  94. printf("%c", tree_Trunk);
  95. }
  96.  
  97. //else if handling base
  98.  
  99. else if (i == tree_Size) {
  100. printf("\n");
  101.  
  102. for (x = 0; x < tree_Size; x++) {
  103. printf("%c", tree_Base);
  104. }
  105.  
  106. printf("%c", tree_Middle);
  107.  
  108. for (x = 0; x < tree_Size; x++) {
  109. printf("%c", tree_Base);
  110. }
  111. }
  112. }
  113. }
  114. }
  115.  
  116. printf("\n");
  117.  
  118. }