圣诞节快到了,这是我到CSDN度过的第一个圣诞节,也是我学习计算机的第一个圣诞节,为了让它更有意义,我呕心沥血,自己打了两版初学者版,再在网上找了一版进阶版,都十分精美,废话少说,代码奉上:

初学者版:

#include<stdio.h>
#include<windows.h>
#include<string.h>
void color(int x)
{if(x>=0 && x<=15)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x); elseSetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
}
void set_Christmastree(char *p){int i,j,n=5,s;color(2); printf("\n");for(i=1;i<=n;i++){if(i==1){for(j=1;j<=i;j++){for(s=1;s<=n+11-j;s++){printf(" ");}for(s=1;s<=2*j-1;s++){printf("*");}printf("\n");}} else{for(j=i;j<=i+1;j++){for(s=1;s<=n+11-j;s++){printf(" ");}for(s=1;s<=2*j-1;s++){if(s==n-3){color(11);printf("%c",p[0]);color(2);continue;      }if(s==n-1){color(5);printf("%c",p[1]);color(2);continue;       }if(s==n+1){color(4);printf("%c",p[2]);color(2);      continue;}if(s==n+3){color(1);printf("%c",p[3]);color(2);continue;}if(s==n+5){color(12);printf("%c",p[4]);color(2);continue;}printf("*");}printf("\n");}}}color(6);for(s=1;s<=n+11;s++){if(s==n+9){printf("|||||\n");color(15);printf("             %c%c%c%c%c",p[5],p[5],p[5],p[5],p[5]);continue;}printf(" ");}printf("\n");for(s=1;s<=36;s++){if(s==n+11){printf("V");continue;}printf("=");}
}
int main(){int t=0;color(11);printf("首先祝这个电脑前的小可爱圣诞快乐(~ ̄▽ ̄)~");printf("\n");printf("接下来有几个选项需要您的选择,你需要我的作者给您画的圣诞树还是自己做一个呢?");printf("\n");printf("看作者的选0,如果想自己做呢选1,祝您开心o(*^@^*)o");printf("您的选择是:");scanf("%d",&t);if(t==0){char l[6]="HAPPYU",m[100]="Merry Christmas.";set_Christmastree(l);color(3);printf("\nI want to say:\n");puts(m);printf("Made by zhanduanwanfeng.");}if(t==1){char k[6],w[100]="Merry Christmas.";printf("请选择您要隐藏的字符,只有六个字符哦,可以有特殊含义(IMISSU,ILOVEU等哦)后面还可加一句你想说的话,与前面字符用空格隔开,字符间不要加空格哦>_<:");scanf("%s",k);gets(w); set_Christmastree(k);color(3); printf("\nI want to say:\n");puts(w);printf("Made by zhanduanwanfeng.");}return 0;
} 

这是效果图:

这是初学者版2,比前一个多了雪花,复杂了些。

#include<stdio.h>
#include<windows.h>
#include<string.h>
void color(int x)
{if(x>=0 && x<=15)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x); elseSetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
}
void set_Christmastree(char *p){  //打印圣诞树和雪景的函数 int i,j,n=5,s,y=0;color(2); printf("\n");for(i=1;i<=n;i++){y++;if(i==1){  //第一层是一个*,之后都是梯形 for(j=1;j<=i;j++){for(s=1;s<=36;s++){if((s<=n+11-j)||(s>=17)){if(s%(i+3)==i){  //雪景 color(15);putchar('*');color(2);}elseprintf(" ");}else if(s==n+11){putchar('*');}}printf("\n");}} else{for(j=i;j<=i+1;j++){  //打印梯形 for(s=1;s<=36;s++){if((s<=n+11-j)||(s>=n+11+j)){if(s%(i+3)==i){  //雪景 color(15);putchar('*');color(2);}elseprintf(" ");}else{if(s==n+2+y){   //这几个if函数都是用来打印圣诞树上的变色字符 color(11);printf("%c",p[0]);color(2);continue;       }else if(s==n+4+y){color(5);printf("%c",p[1]);color(2);continue;      }else if(s==n+6+y){color(4);printf("%c",p[2]);color(2);      continue;}else if(s==n+8+y){color(1);printf("%c",p[3]);color(2);continue;}else if(s==n+10+y){color(12);printf("%c",p[4]);color(2);continue;}elseprintf("*");}}printf("\n");}}}color(6);for(s=1;s<=34;s++)  //树桩 {if(s==n+9){color(15);printf("*  *  *  *  *");color(6);printf("|||||");color(15);printf(" *  *  *  *  * \n");printf("*  *  *  *  *%c%c%c%c%c *  *  *  *  *  ",p[5],p[5],p[5],p[5],p[5]);continue;}/*else{color(15);printf("* ");//color(6);}*/}printf("\n");for(s=1;s<=34;s++){if(s==n+11){printf("V");continue;}else printf("=");}
}
int main(){int t=0;color(11);printf("首先祝这个电脑前的小可爱圣诞快乐(~ ̄▽ ̄)~");printf("\n");printf("接下来有几个选项需要您的选择,你需要我的作者给您画的圣诞树还是自己做一个呢?");printf("\n");printf("看作者的选0,如果想自己做呢选1,祝您开心o(*^@^*)o");printf("您的选择是:");scanf("%d",&t);if(t==0){char l[6]="HAPPYU",m[100]="Merry Christmas.";set_Christmastree(l);color(3);printf("\nI want to say:\n");puts(m);printf("Made by zhanduanwanfeng.");}if(t==1){char k[6],w[100]="Merry Christmas.";printf("请选择您要隐藏的字符,只有六个字符哦,可以有特殊含义(IMISSU,ILOVEU等哦)后面还可加一句你想说的话,与前面字符用空格隔开,字符间不要加空格哦>_<:");scanf("%s",k);gets(w); set_Christmastree(k);color(3); printf("\nI want to say:\n");puts(w);printf("Made by zhanduanwanfeng.");}return 0;
} 

这是效果图:

以下是进阶版,更炫:

#include <windows.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define PI 3.14159265359
#define T px + scale * r * cosf(theta), py + scale * r * sin(theta)
float sx, sy;
float sdCircle(float px, float py, float r) {float dx = px - sx, dy = py - sy;return sqrtf(dx * dx + dy * dy) - r;
}
float opUnion(float d1, float d2) {return d1 < d2 ? d1 : d2;
}
float f(float px, float py, float theta, float scale, int n) {float d = 0.0f;for (float r = 0.0f; r < 0.8f; r += 0.02f)d = opUnion(d, sdCircle(T, 0.05f * scale * (0.95f - r)));if (n > 0)for (int t = -1; t <= 1; t += 2) {float tt = theta + t * 1.8f;float ss = scale * 0.9f;for (float r = 0.2f; r < 0.8f; r += 0.1f) {d = opUnion(d, f(T, tt, ss * 0.5f, n - 1));ss *= 0.8f;}}return d;
}
int ribbon() {float x = (fmodf(sy, 0.1f) / 0.1f - 0.5f) * 0.5f;return sx >= x - 0.05f && sx <= x + 0.05f;
}
int main(int argc, char* argv[]) {int n = argc > 1 ? atoi(argv[1]) : 3;float zoom = argc > 2 ? atof(argv[2]) : 1.0f;for (sy = 0.8f; sy > 0.0f; sy -= 0.02f / zoom, putchar('\n'))for (sx = -0.35f; sx < 0.35f; sx += 0.01f / zoom) {if (f(0, 0, PI * 0.5f, 1.0f, n) < 0.0f) {if (sy < 0.1f) {putchar('.');} else {if (ribbon()) {putchar('=');} else {putchar("............................#j&o"[rand() % 32]);}}} else {putchar(' ');}}Sleep(1000);printf("\n\n\n");for (size_t i = 0; i < 40; i++) {putchar(' ');}//_sleep(5000);printf("Merry Christmas, baby~!\n");Sleep(500);for (size_t i = 0; i < 40; i++) {putchar(' ');}printf("Never say die.\n");Sleep(500);for (size_t i = 0; i < 40; i++) {putchar(' ');}printf("2016/12/24, 最爱你的UP主\n");getchar();
}

效果图就不放了,感兴趣可以试试,很炫哦。

感谢观看,敬请关注收藏。

C语言圣诞树(精修版)附图(有初学者版还有进阶版)相关推荐

  1. 全国计算机二级考试c语言指针,全国计算机二级考试C语言 指针精讲课件.ppt

    全国计算机二级考试C语言 指针精讲课件 第七章:指 针;第一节:指针概述;如:执行以下说明语句后: int a=3,b=4; float c=4.5,d=8.6; char e='x',f='y';其 ...

  2. 《C语言编程——零基础初学者指南(第3版)》一第1章 什么是C程序设计1.1 什么是程序...

    本节书摘来自异步社区<C语言编程--零基础初学者指南(第3版)>一书中的第1章,第1.1节,作者 [美]Greg Perry , Dean Miller,更多章节内容可以访问云栖社区&qu ...

  3. 啦啦啦一棵R语言圣诞树~

    R语言圣诞树 一棵R语言圣诞树 代码 效果图 一棵R语言圣诞树 一个R语言圣诞树来应景,花了菜菜的我一整节禅宗与文学课哈哈哈~ 后天就要考R语言了嘤嘤嘤QAQ 代码 ChrimasTree<-f ...

  4. c语言精华版课件,C语言课件精华版).ppt

    C语言课件精华版) 计算机基础教学系列课程;课程性质: 大学生公共基础课程 (必修课) 学时: 讲课 34课时; 实验 64 (课内32/课外32) 学分: 2学分总评成绩 = 平时成绩 40%+ 期 ...

  5. 一台计算机安装了fortran语言,第一章计算机Fortran语言简介精要.ppt

    第一章计算机Fortran语言简介精要.ppt 第1章 计算机与Fortran语言简介 知道计算机的基本构造 理解二进制系统 Fortran的历史和现状 内容简介: 1.1 计算机 CPU (cent ...

  6. 嵌入式C语言数据结构精讲-曹国辉-专题视频课程

    嵌入式C语言数据结构精讲-236人已学习 课程介绍         系统学习嵌入式开发中常用的数据结构知识,包括顺序表,链表,栈和队列. 包括理论讲解和代码实现,配套课件和源码资料齐全,代码全部采用C ...

  7. 2022计算机全程:C语言程序设计精讲

    01.第一章C语言的概述.mp4     大小:152.79 M 02.第二章数据类型.运算符及表达式(一).mp4     大小:114.09 M 03.第二章数据类型.运算符及表达式(二).mp4 ...

  8. 数据结构殷人昆电子版百度云资源_数据结构精讲与习题详解(C语言版第2版清华大学计算机系列教材)...

    导语 内容提要 殷人昆编著的<数据结构精讲与习题详解(C语言版第2版清华大学计算机系列教材)>是清华大学出版社出版的<数据结构(C语言版)>(第2版)的配套教材,对" ...

  9. Oracle数据库精讲与疑难解析(第2版)

    Oracle数据库精讲与疑难解析(第2版) 赵振平编著 ISBN978-7-121-20021-2 2013年4月出版 定价:148.00元 1100页 16开 编辑推荐 耗时3年,作者曾为本书辞职在 ...

最新文章

  1. MVC控件类型-HtmlHelper类
  2. 趋势修改服务器地址,趋势客户端修改连接服务器
  3. SQL Server 2017 AlwaysOn on Linux 配置和维护(18)
  4. 如何将两个集合合并_如何将剪切的音频文件进行合并
  5. 前后端项目中跨域问题
  6. java list子类_List集合的子类ArrayList、LinkedList、Vector
  7. Ibatis - Open quote is expected for attribute {1} associated with an element type '
  8. JsonView插件的使用
  9. Hpdl80服务器硬件驱动,hpe proliant dl80 gen9服务器用户指南.pdf
  10. java卡 应用_一种实现多发行方的多应用Java卡的方法与流程
  11. security工作笔记003---SpringSecurity框架启动报错.bcrypt.BCryptPasswordEncoder‘ that could not be found.
  12. 策略模式【设计模式学习-02】
  13. 从伊朗虚假新闻活动案例来看国外造谣及传谣模式
  14. java sam接口,Java中的SAM接口是什么?
  15. Python爬虫随笔
  16. 【计算机体系结构】非线性流水线调度算法 C++ Python
  17. 12、MTU的概念,什么是路径MTU? MTU发现机制,TraceRoute(了解)
  18. Confluent介绍(一)
  19. 程序员团队名称和口号_这50个团建活动的口号,你曾经叫过几次呢?
  20. 商用密码应用与安全性评估之(二)商用密码管理法律法规

热门文章

  1. 网易免费邮箱的smtp 为何密码错误
  2. tensorflow:tensorflow进阶
  3. 注销consul节点
  4. 我100米跑了7秒会不会太慢了
  5. 开源了自己开发的后台管理系统
  6. 【拜占庭将军问题】这一计谋,可以让诸葛丞相兴复汉室
  7. 电脑文件删不掉怎么办?数据误删也能恢复
  8. 面试了几十家软件测试公司全是这个“套路”
  9. [原创]服装鞋帽企业配送中心优化方案 WMS仓储管理系统
  10. 可以过滤网页中广告的插件Adblock Plus