c语言动态圣诞树代码
时间: 2023-12-14 08:34:15 浏览: 152
以下是C语言动态圣诞树代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define TREE_HEIGHT 20
int main() {
int i, j, k;
int tree_width = TREE_HEIGHT * 2 - 1;
char tree[tree_width][TREE_HEIGHT];
memset(tree, ' ', sizeof(tree));
while (1) {
for (i = 0; i < TREE_HEIGHT; i++) {
for (j = 0; j < tree_width; j++) {
if (j >= TREE_HEIGHT - i - 1 && j <= TREE_HEIGHT + i - 1) {
tree[j][i] = '*';
}
}
}
for (i = 0; i < TREE_HEIGHT; i++) {
for (j = 0; j < tree_width; j++) {
printf("%c", tree[j][i]);
}
printf("\n");
}
for (k = 0; k < TREE_HEIGHT / 2 k++) {
printf("%*s||\n", TREE_HEIGHT, "");
}
usleep(500000);
system("clear");
memset(tree, ' ', sizeof(tree));
}
return 0;
}
```
阅读全文