Draw Christmas Tree in C: Complete Code Tutorial
Here is a simple sample code in C language to draw a Christmas tree.
#include <stdio.h>
int main() {
int i, j, k;
int rows = 10; // 圣诞树的行数
for (i = 0; i < rows; i++) {
for (j = 0; j < rows - i - 1; j++) {
printf(" "); // 打印空格
}
for (k = 0; k < 2*i + 1; k++) {
printf("*"); // 打印圣诞树的主干
}
printf("\n");
}
for (i = 0; i < 3; i++) {
for (j = 0; j < rows - 2; j++) {
printf(" "); // 打印空格
}
for (k = 0; k < 5; k++) {
printf("*"); // 打印圣诞树的树梢
}
printf("\n");
}
return 0;
}
This code will print a simple Christmas tree shape, and you can adjust the value of rows as needed to control the size of the Christmas tree.