Re: [問卦] 慟!有沒有程式不會寫的八卦?已回收
※ 引述《jeffery95099 (傑佛里95099)》之銘言:
: 安安
: 是這樣啦
: 本肥宅在練習寫程式
: 題目是要輸出一個中間是空心菱形的正方形啦
: 邊長由使用者輸入且必為奇數
: 大guy4長這樣啦
: *****
: ** **
: * *
: ** **
: *****
: 這樣要怎麼寫啊
: 本肥宅苦思已久還是想不出來
: 有卦嗎
: 嘻嘻
給你參考拉
n 為輸入奇數
以下開始我的構思
m=(n+1)/2
for i=1 to n
if i=1 or i=n then
//頭尾都*
for j=1 to n
輸出*
next
elseif i<m then
//上三角形
for j=1 to n
if abs(j-m)>=i-1 then
輸出*
else
輸出空白
end if
next
elseif i=m then
//中間
for j=1 to n
if j=1 or j=n then
輸出*
else
輸出空白
end if
next
elseif i>m then
//下三角形
for j=1 to n
if abs(i-m)+abs(j-m)>(m+1)/2 then
輸出*
else
輸出空白
end if
next
end if
輸出下一行
next
---------------------------
試試看吧 有錯別問我
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 175.180.226.191
※ 文章網址: https://www.ptt.cc/bbs/Gossiping/M.1546966725.A.FDE.html
→
01/09 00:59,
7年前
, 1F
01/09 00:59, 1F
→
01/09 00:59,
7年前
, 2F
01/09 00:59, 2F
→
01/09 00:59,
7年前
, 3F
01/09 00:59, 3F
→
01/09 00:59,
7年前
, 4F
01/09 00:59, 4F
→
01/09 00:59,
7年前
, 5F
01/09 00:59, 5F
→
01/09 01:01,
7年前
, 6F
01/09 01:01, 6F
→
01/09 01:10,
7年前
, 7F
01/09 01:10, 7F
→
01/09 01:10,
7年前
, 8F
01/09 01:10, 8F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):