看板 Programming 關於我們 聯絡資訊
實在想不通...不知道有沒有大大可以提供一下意見...。 #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
programming:難道寫的方向錯了@@? 210.60.64.23 04/28 23:33
wupojung:修改的 範圍可大了.. 203.67.210.42 04/29 01:07
bobju:哇~這難度顯然更高. 59.104.191.26 04/29 01:09
march20:想維持原結構但又想改成並排 128.54.47.73 04/29 07:23
march20:嗯, 把 printf 改成寫到 buffer 去 128.54.47.73 04/29 07:23
march20:然後一口氣印出三組 buffer 吧 128.54.47.73 04/29 07:23