C language design A sparkling Christmas tree _c language

Source: Internet
Author: User
Tags rand

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.