題目:數字菱形圖
輸入一個N,印出一數字菱形圖
輸入格式:大於0、小於10之正整數。
輸出格式:如輸入範例
輸入範例:N=3
輸出範例:
***0
**010
*01210
0123210
*01210
**010
***0
PS: \"*\" 不要看,看那個數字跟菱形就好。
請問這樣的程式該怎麼寫。
越簡單越明瞭,越好。
2006-08-28 11:23:04 · 5 個解答 · 發問者 古董 1 in 電腦與網際網路 ➔ 程式設計
來湊一腳..Private Sub Form_Activate() Do N = Val(InputBox("輸入大於0、小於10之正整數")) Loop Until (N > 0 And N < 10) i = 0 Do j = 0: flag2 = False Print Space((N - i) * 4); '印出左邊的空白縮排 Do Print j; '印出 j If (j = i) Then flag2 = True ' 一開始j會一直增加,加到與i相等就改變flag2 j = IIf(flag2, j - 1, j + 1) '以flag2來判斷 j是要+1或-1 Loop Until (j < 0) Print '換行 If (i = N) Then flag = True '這邊的原理跟 j迴圈內的一樣 i = IIf(flag, i - 1, i + 1) Loop Until (i < 0)End Sub
2006-08-29 06:20:26 · answer #1 · answered by ? 6 · 0⤊ 0⤋
阿戊做得好...^^~
2006-08-28 20:10:14 · answer #2 · answered by ? 4 · 0⤊ 0⤋
'Power by Visual Studio 2005Module Module1 Sub Main() '=====START=====' Dim i%, j%, intNUM% Console.Write("輸入大於 0 、小於 10 的正整數值:") intNUM = Console.ReadLine intNUM *= 2 For i = 0 To intNUM Step 1 If (i <= intNUM \ 2) Then For j = 0 To (intNUM \ 2 - 1) - i Step 1 Console.Write(" ") Next ElseIf i > intNUM \ 2 Then For j = 0 To i - (intNUM \ 2 + 1) Step 1 Console.Write(" ") Next End If If (i <= intNUM \ 2) Then For j = 0 To i Step 1 Console.Write("{0}", j) Next ElseIf (i > intNUM \ 2) Then For j = 0 To intNUM - i Step 1 Console.Write("{0}", j) Next End If If (i <= intNUM \ 2) Then For j = i - 1 To 0 Step -1 Console.Write("{0}", j) Next ElseIf (i > intNUM \ 2) Then For j = intNUM - i - 1 To 0 Step -1 Console.Write("{0}", j) Next End If Console.WriteLine("") Next '=====END=====' Console.Write("請按任何鍵繼續 . . .") Console.ReadLine() End SubEnd Module
2006-08-28 12:32:54 · answer #3 · answered by Big_John-tw 7 · 0⤊ 0⤋
Private Sub Form_Activate()
Form1.FontName = "細明體":Cls
reinput:
n = Val(InputBox("請輸入一個大於0,小於10的正整數:"))
If n <= 0 Or n >= 10 Then GoTo reinput
For I = 0 To n * 2
Print String(Abs(n - I), " ");
For j = 0 To (n - Abs(n - I)): Print Format(j);: Next j
For j = n - Abs(n - I) - 1 To 0 Step -1: Print Format(j);: Next j
Print
Next I
End Sub
2006-08-28 12:29:10 · answer #4 · answered by ? 7 · 0⤊ 0⤋
Private Sub Form_Activate()
NUM = InputBox("請輸入一個大於0,小於10的正數字:")
For I = 0 To NUM
Print Spc(NUM - I);
For J = 0 To I
Print Trim(Str(J));
Next
For K = I - 1 To 0 Step -1
Print Trim(Str(K));
Next K
Print
Next I
For I = NUM - 1 To 0 Step -1
Print Spc(NUM - I);
For J = 0 To I
Print Trim(Str(J));
Next
For K = I - 1 To 0 Step -1
Print Trim(Str(K));
Next K
Print
Next I
End Sub
2006-08-28 12:21:12 · answer #5 · answered by 丁子 7 · 0⤊ 0⤋