#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int Height, Length, Width, Leaf, Stem, Index;
A:printf("请输入你想要圣诞叶的高度(0~39且为奇数):");
scanf("%d",&Height);
Width = Height*2-1;
Length = Height/2;
if ((Height > 0)&&(Height < 40)&&(Height%2 != 0))
{
for (Leaf = 0; Leaf < Height; Leaf++)
{
for (Index = 1; Index <= Width; Index++)
{
if ((Index <= Height+Leaf)&&(Index >= Height-Leaf))
printf("*");
else
printf("-");
}
printf("\n");
}
for (Stem = 0; Stem < Length; Stem++)
{
for (Index = 1; Index <= Width; Index++)
{
if (Index == Height)
printf("*");
else
printf("-");
}
printf("\n");
}
}
}
上面的程式会以输出字串的方式绘出圣诞树,层与层之间没有空白行,树叶部分及树干都是由 '*' 代表,背景以 '-' (减号)代表,树干位於树的中央。该程式会读取使用者输入的一个3到39的奇数,该数字代表三角形部分的高度(H),树干部分的长度(L)等於(H/2)取整数。树的宽度(W)等於(H*2-1),单位为字元。
【问题】
请修改该程式以满足下面所述的需求
1. 使用者可以一次输入3棵树的高度
2. 程式必须并列印出使用者输入的三个高度的圣诞树树,树与树之间需有空格
3. 程式中必须利用到函数的概念
范例输出
使用者输入5, 5, 3(下面格式好像乱掉了,就是让3棵树并排而不是换到下一行)
----*---- ----*---- --*--
---***--- ---***--- -***-
--*****-- --*****-- *****
-*******- -*******- --*--
********* *********
----*---- ----*----
----*---- ----*----