作者programming (复制自己)
看板C_and_CPP
标题[问题] C语言圣诞树并排
时间Tue Apr 28 23:51:14 2009
实在想不通...不知道有没有大大可以提供一下意见...。
#include<stdio.h>
#include<stdlib.h>
void tree(int x);
int main()
{
int Height, Length, Width, Leaf, Stem, Index, Heightt, Heighttt;
printf("请输入你想要圣诞叶的高度(0~39且为奇数):");
scanf("%d,%d,%d",&Height,&Heightt,&Heighttt);
tree(Height);
tree(Heightt);
tree(Heighttt);
Width = Height*2-1;
Length = Height/2;
system("pause");
return 0;
}
void tree(int x)
{int Height, Length, Width, Leaf, Stem, Index, Heightt, Heighttt;
Width = x*2-1;
Length = x/2;
if ((x > 0)&&(x < 40)&&(x%2 != 0))
{
for (Leaf = 0; Leaf < x; Leaf++)
{
for (Index = 1; Index <= Width; Index++)
{
if ((Index <= x+Leaf)&&(Index >= x-Leaf))
printf("*");
else
printf("-");
}
printf("\n");
}
for (Stem = 0; Stem < Length; Stem++)
{
for (Index = 1; Index <= Width; Index++)
{
if (Index == x)
printf("*");
else
printf("-");
}
printf("\n");
}
}
return;
}
可显示出三颗串联的圣诞树...
如图:
--*--
-***-
*****
--*--
----*----
---***---
--*****--
-*******-
*********
----*----
----*----
------*------
-----***-----
----*****----
---*******---
--*********--
-***********-
*************
------*------
------*------
------*------
可是我想改成"并排"的三棵圣诞树,如图
--*-- ----*---- ------*------
-***- ---***--- -----***-----
***** --*****-- ----*****----
--*-- -*******- ---*******---
********* --*********--
----*---- -***********-
----*---- *************
------*------
------*------
------*------
试了一天...还是改不出来QQ
怎麽会这样ˊˋ
有大大会的吗QQ?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.60.64.23
1F:推 gozha:大绝招:Turbo C #include<dos.h> gotoxy(x, y); 囧 04/29 00:08
2F:推 IamCoolKing:勾炸的c也这麽强噢 (惊!) 04/29 00:09
3F:→ sunneo:可以弄char[25][80] 在里面各个位置画 04/29 00:10
4F:→ IamCoolKing:楼上的也是一个方法 04/29 00:15
5F:推 VictorTom:小弟想到前几天的双月并排的月历, 而且看到并排的树就 04/29 00:31
6F:→ VictorTom:知道一定会有人推[25][80]....XDDD 04/29 00:32
7F:→ sunneo:呵呵 25 80是ms的console的全萤幕预设 04/29 00:52
8F:→ sunneo:以往我蛮喜欢这麽做的 特别是假使每个都有颜色设定 04/29 00:52
9F:→ sunneo:则可以开个short[25][80],前8bit存颜色,後8bit放字 04/29 00:53
10F:推 VictorTom:说到25 80, 除非不care卷动, 不然小弟以前好像最多只用 04/29 04:07
11F:→ VictorTom:24 80, 不然在25 80写完char一自动换行, 就回不来了XD 04/29 04:07
12F:→ VictorTom:如果每个frame都会全部更新就没这个问题:) 04/29 04:08
13F:→ sprinter:是作业吗? 好像一年多前曾经看过 04/29 19:55