作者mosluce ()
看板C_Sharp
標題Re: [問題] 畫一個漏斗圖案
時間Fri Jul 23 21:31:24 2010
int n = 5; //or 3,7,9,11...etc..
int lines = n;
int center = (n+1)/2;
for(int i=0; i<center; i++){
String str = new String('*', 5-i*2);
Console.WriteLine(str);
}
for(int i=0; i<center-1; i++){
String str = new String('*', 2*i+3);
Console.WriteLine(str);
}
//應該吧=w=~
//不知是否有誤
※ 引述《party100046 (陳靖仇)》之銘言:
: 我在練習畫一個漏斗出來
: 像是這樣的
: *****
: ***
: *
: ***
: *****
: 但是怎麼畫好像都只有畫一個三角形而已
: 我上下的形狀都有寫判斷式了
: 想來請問版上的大大們,那裡的邏輯出了問題?
: 以下是我的程式碼
: int x,y,center;
: center = (x + 1) / 2;
: for (x = 1; x <= 5; x++)
: {
: for (y = 1; y <= 5; y++)
: {
: if (y <= center + (3 - x))
: {
: System.Console.WriteLine("*");
: }
: else if (y <= center + (x - 3))
: {
: System.Console.WriteLine("*");
: }
: else
: {
: System.Console.WriteLine("");
: }
: }
: }
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.64.179.182
推 F23ko:等等.... 你好像忘了畫空白鍵 07/23 23:49
推 party100046:對...沒有畫空白= =" 07/24 00:30