欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C語(yǔ)言設(shè)計(jì)一個(gè)閃閃的圣誕樹

 更新時(shí)間:2016年12月15日 10:20:03   投稿:mrr  
本文使用C語(yǔ)言基礎(chǔ)知識(shí)在控制臺(tái)打印一個(gè)圣誕樹效果,真的很簡(jiǎn)單哦,一起通過本文學(xué)習(xí)吧

控制臺(tái)打印一個(gè)圣誕樹:簡(jiǎn)簡(jiǎn)單單的C語(yǔ)言知識(shí),真的很基礎(chǔ),小白也能看得懂哦

/*******************************
圣誕樹
byC語(yǔ)言小白入門
*******************************/
#include<stdio.h>
#include <stdlib.h>
#include <time.h>
#include<Windows.h>
#define X 25 //畫面長(zhǎng)度
int background[20][2 * X] = { 0 };
int SNOW = 30; //雪花密度
/*******************************
畫樹
*******************************/
void tree()
{
int i, j, x, y;
for (i = 0; i < 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++;
for (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;
}
}
for (i = 0; i < 5; i++)
{
y++;
for (j = 0; j < 3; j++)
{
background[y][X + (2 * j - 2)] = 2;
}
}
}
/*******************************
畫雪花
*******************************/
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;
}
}
}
/*******************************
打印
*******************************/
void display()
{
int x, y;
for (y = 0; y < 20; y++)
{
for (x = 0; x < 2 * X; 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)
{
printf("*");
}
}
printf("\n");
}
}
/*******************************
清除雪花
*******************************/
void clear_snow()
{
int i, j;
for (i = 0; i < 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();
}
}

最終的效果圖

也沒有那么高大上的啦,就很簡(jiǎn)單的,效果的話是動(dòng)態(tài)的,可以閃動(dòng)的呢。

如果大家看以上代碼不過癮,大家可以參考下這篇文章。

使用C語(yǔ)言編寫圣誕表白程序

以上所述是小編給大家介紹的C語(yǔ)言設(shè)計(jì)一個(gè)閃閃的圣誕樹,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論