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

看板C_and_CPP作者 (複製自己)時間16年前 (2009/04/28 15:51), 編輯推噓4(409)
留言13則, 5人參與, 最新討論串1/4 (看更多)
實在想不通...不知道有沒有大大可以提供一下意見...。 #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/29 00:08, , 1F
大絕招:Turbo C #include<dos.h> gotoxy(x, y); 囧
04/29 00:08, 1F

04/29 00:09, , 2F
勾炸的c也這麼強噢 (驚!)
04/29 00:09, 2F

04/29 00:10, , 3F
可以弄char[25][80] 在裡面各個位置畫
04/29 00:10, 3F

04/29 00:15, , 4F
樓上的也是一個方法
04/29 00:15, 4F

04/29 00:31, , 5F
小弟想到前幾天的雙月併排的月曆, 而且看到並排的樹就
04/29 00:31, 5F

04/29 00:32, , 6F
知道一定會有人推[25][80]....XDDD
04/29 00:32, 6F

04/29 00:52, , 7F
呵呵 25 80是ms的console的全螢幕預設
04/29 00:52, 7F

04/29 00:52, , 8F
以往我蠻喜歡這麼做的 特別是假使每個都有顏色設定
04/29 00:52, 8F

04/29 00:53, , 9F
則可以開個short[25][80],前8bit存顏色,後8bit放字
04/29 00:53, 9F

04/29 04:07, , 10F
說到25 80, 除非不care捲動, 不然小弟以前好像最多只用
04/29 04:07, 10F

04/29 04:07, , 11F
24 80, 不然在25 80寫完char一自動換行, 就回不來了XD
04/29 04:07, 11F

04/29 04:08, , 12F
如果每個frame都會全部更新就沒這個問題:)
04/29 04:08, 12F

04/29 19:55, , 13F
是作業嗎? 好像一年多前曾經看過
04/29 19:55, 13F
文章代碼(AID): #19zoNpdk (C_and_CPP)
文章代碼(AID): #19zoNpdk (C_and_CPP)