fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int layers;
  5.  
  6. printf("#Create the Christmas Tree#\n");
  7. printf("Enter the number of the first leaf layer (3-19): ");
  8. scanf("%d", &layers);
  9.  
  10. // ตรวจสอบค่า input
  11. if (layers < 3 || layers > 19) {
  12. printf("Invalid input. Please enter a number between 3 and 19.\n");
  13. return 1;
  14. }
  15.  
  16. // วาด first leaf layer
  17. for (int i = 0; i < layers; i++) {
  18. for (int j = 0; j < layers - i - 1; j++) {
  19. printf(" ");
  20. }
  21. for (int k = 0; k < 2 * i + 1; k++) {
  22. printf("*");
  23. }
  24. printf("\n");
  25. }
  26.  
  27. // วาด second leaf layer
  28. for (int i = 0; i < layers - 1; i++) {
  29. for (int j = 0; j < layers - i - 2; j++) {
  30. printf(" ");
  31. }
  32. for (int k = 0; k < 2 * i + 3; k++) {
  33. printf("*");
  34. }
  35. printf("\n");
  36. }
  37.  
  38. // วาดลำต้นของต้นคริสต์มาส
  39. for (int i = 0; i < 2; i++) {
  40. for (int j = 0; j < layers - 2; j++) {
  41. printf(" ");
  42. }
  43. printf("***\n");
  44. }
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0.01s 5272KB
stdin
3
stdout
#Create the Christmas Tree#
Enter the number of the first leaf layer (3-19):   *
 ***
*****
 ***
*****
 ***
 ***