作者programming (复制自己)
看板Programming
标题[问题] c语言圣诞树并排
时间Tue Apr 28 23:27:49 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:→ programming:难道写的方向错了@@? 210.60.64.23 04/28 23:33
2F:推 wupojung:修改的 范围可大了.. 203.67.210.42 04/29 01:07
3F:推 bobju:哇~这难度显然更高. 59.104.191.26 04/29 01:09
4F:推 march20:想维持原结构但又想改成并排 128.54.47.73 04/29 07:23
5F:推 march20:嗯, 把 printf 改成写到 buffer 去 128.54.47.73 04/29 07:23
6F:推 march20:然後一口气印出三组 buffer 吧 128.54.47.73 04/29 07:23