【急!】用C语言排圣诞树,要怎麼让结果呈现并排?

#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棵树并排而不是换到下一行)
----*---- ----*---- --*--
---***--- ---***--- -***-
--*****-- --*****-- *****
-*******- -*******- --*--
********* *********
----*---- ----*----
----*---- ----*----

#include<stdio.h>
#include<stdlib.h>
int len(int h);
int max(int x,int y,int z);
int min(int x,int y,int z);
void main()
{ int i,j,k;
printf("请输入你想要圣诞叶的高度(0~39且为奇数):");
scanf("%d%d%d",&i,&j,&k);
int Height,Length, Width, Leaf, Smax,Smin, Index;
Height=i;
Smax=max(i,j,k);
Smin=min(i,j,k);
Length = max(i,j,k)/2;
Width =(i+j+k)*2-1;
if ((Height > 0)&&(Height< 40)&&(Height%2 != 0))
{
for (Leaf = 0; Leaf <Smax+Length; Leaf++)
{ if(Leaf<Smin)
{for (Index = 1; Index <= Width; Index++)
{
if ((((Index <= Height+Leaf)&&(Index >= Height-Leaf)&&(Leaf<i))
||(((Index <= Height+Leaf+j+i)&&(Index >= Height-Leaf+j+i))&&(Leaf<j))
||(((Index <= Height+Leaf+j+i+j+k)&&(Index >= Height-Leaf+j+i+j+k)))&&(Leaf<k)))
printf("*");
else
if((Index==2*i)||(Index==2*i+2*j))
printf(" ");
else
printf("-");
}
printf("\n");

}
else
{if(Leaf<Smax)
{

for (Index = 1; Index <= Width; Index++)
{
if (((Index == Height)&&(Leaf<i+len(i)))
||((Index == Height+j+i)&&(Leaf<j+len(j)))
||((Index == Height+j+i+j+k)&&(Leaf<k+len(k)))
||(((Index <= Height+Leaf)&&(Index >= Height-Leaf)&&(Leaf<i))
||(((Index <= Height+Leaf+j+i)&&(Index >= Height-Leaf+j+i))&&(Leaf<j))
||(((Index <= Height+Leaf+j+i+j+k)&&(Index >= Height-Leaf+j+i+j+k)))&&(Leaf<k)))
printf("*");
else
if((Index==2*i)||(Index==2*i+2*j))
printf(" ");
else
printf("-");
}
printf("\n");
}

else
{
for (Index = 1; Index <= Width; Index++)
{
if (((Index == Height)&&(Leaf<i+len(i)))
||((Index == Height+j+i)&&(Leaf<j+len(j)))
||((Index == Height+j+i+j+k)&&(Leaf<k+len(k))))

printf("*");
else
if((Index==2*i)||(Index==2*i+2*j))
printf(" ");
else
printf("-");
}
printf("\n");
}
}
}
}
}
int len(int h)
{ return h/2;
}
int max(int x,int y,int z)
{ if(x>y&&x>z)
return x;
if(y>x&&y>z)
return y;
if(z>x&&z>y)
return z;
}
int min(int x,int y,int z)
{ if(x<y&&x<z)
return x;
if(y<x&&y<z)
return y;
if(z<x&&z<y)
return z;
}

空白处未解决,基本已实现其功能~~
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-05-15
晕!!!正立的正三角形会编写不 基本一样