[問題] c語言聖誕樹並排

看板Programming作者 (複製自己)時間16年前 (2009/04/28 15:27), 編輯推噓5(501)
留言6則, 4人參與, 最新討論串1/3 (看更多)
實在想不通...不知道有沒有大大可以提供一下意見...。 #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

04/28 23:33, , 1F
難道寫的方向錯了@@?
04/28 23:33, 1F

04/29 01:07, , 2F
修改的 範圍可大了..
04/29 01:07, 2F

04/29 01:09, , 3F
哇~這難度顯然更高.
04/29 01:09, 3F

04/29 07:23, , 4F
想維持原結構但又想改成並排
04/29 07:23, 4F

04/29 07:23, , 5F
嗯, 把 printf 改成寫到 buffer 去
04/29 07:23, 5F

04/29 07:23, , 6F
然後一口氣印出三組 buffer 吧
04/29 07:23, 6F
文章代碼(AID): #19zo1sQ- (Programming)
文章代碼(AID): #19zo1sQ- (Programming)