Console Print a Christmas tree: simple C language knowledge, really very basic, small white also can see understand oh
/******************************* Christmas Tree BYC language small white primer *******************************/#include <stdio.h> #include
<stdlib.h> #include <time.h> #include <Windows.h> #define X 25//Screen length int background[20][2 * x] = {0}; int SNOW = 30; Snowflake density/******************************* *******************************/void tree () {int I, j, X, y; for (i = 0; I &l T 3; i++) {y = i; for (j = 0; J < 2 * i + 1; j + +) {background[y][(x-i) + j] = 1;} for (i = 0; i < 5; i++) {y++; f
or (j = 0; J < 2 * (i + 1) + 1; j +) {background[y][(X-(i + 1)) + j] = 1;} for (i = 0; i < 7; i++) {y++; for (j = 0; J < 2 * (i + 3) + 1; j +) {background[y][(X-(i + 3)) + j] = 1;}
(i = 0; i < 5; i++)
{y++ for (j = 0; J < 3; J + +) {background[y][x + (2 * j-2)] = 2;}} /******************************* Draw Snowflakes *******************************/void Snow () {int i; Srand (Time (NULL)); for (i = 0 ; i < SNOW;
i++) {int x, y; x = rand ()% (2 * x); y = rand ()% 20;if ((background[y][x] = = 0)) {background[y][x] = 3;}} /******************************* print *******************************/void display () {int x, y; for (y = 0; y < y
+ +) {for (x = 0; x < 2 * x + + +) {if (background[y][x] = = 0) {printf ("");} if (background[y][x] = = 1) {printf ("0");} if (background[y][x] = = 2) {printf ("|");} if (background[y][x] = = 3) {print
F ("*");
printf ("\ n"); }/******************************* clear Snowflake *******************************/void Clear_snow () {int i, J; for (i = 0; ; 20;
i++) {for (j = 0; J < 2 * X; j +) {if (background[i][j] = = 3) {Background[i][j] = 0;}}}
void Main () {tree (), while (1) {snow (); display ();
Sleep (1);
System ("CLS");
Clear_snow (); }
}
The final effect chart
Also not so big on the, it is very simple, the effect of words is dynamic, can be flashing it.
If you look at the above code is not enjoyable, you can refer to this article.
Use c language to write Christmas confession program
The above is a small set to introduce the C language design a sparkling Christmas tree, I hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!