English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

蠻簡單的.......1234543212345 5432345   54345     545       545     54345   5432345 5432123454321請用兩種不同概念的方法寫....嗯....從頭Print到尾的白癡方法不算.....:>

2006-07-10 14:07:17 · 4 個解答 · 發問者 ? 5 in 電腦與網際網路 程式設計

忘了說....
這是是當N=5時的情況
N為奇數 且大於等於3
要可以隨意便動N ^^

2006-07-10 14:16:18 · update #1

剛剛打錯....... Orz

N>=2,不限奇偶
請解題

2006-07-10 14:18:19 · update #2

感謝兩位大大的回答 ^^
明忠大大的方法是由字串的兩邊各別累加上需要的數字
最後再印出來
愁痕大的方法是把資料分為四個部份和空白各別印出來
都非常的精彩 ^^

不過.....................我好像說是兩種概念
怎麼都只看到一種 @@"

2006-07-11 07:16:28 · update #3

4 個解答

終於,寫出第一種+程式碼簡潔化了...睡覺去Private Sub Command1_Click()   Cls   Dim N:    N = InputBox("輸入N")   If (N < 2 Or Not IsNumeric(N)) Then MsgBox "輸入不合法,或N < 2!": Exit Sub   For i = 1 To N      tmp = IIf(i <> N, tmp & i & i, tmp & i)   Next   '// n_ln為第一行的長度 flag=true=先印上半部   n_ln = Len(tmp):   flag = True:   i = 0   Do      i = IIf(flag, i + 1, i - 1)      If i > N Then i = N - 1: flag = False '// 印完上半部後改印下半部      If (Not flag And i < 1) Then Exit Do      out1 = Numstr(i, N, 0)      Print out1;             '// 輸出左半邊      If i = 1 Then           '// 第一行與最後一行的額外處理         Print Numstr(i, N - 1, 1)      Else         out2 = Numstr(i, N, 1)         '// 印空白及右半邊         Print Spc(n_ln - (Len(out1) + Len(out2))); out2      End If   LoopEnd Sub'從St 串接到 Ed的文字函數,OutType分辨遞增遞減Public Function Numstr(ByVal St%, ByVal Ed%, OutType As Byte) As String   If OutType Then      For i = Ed To St Step -1:         Numstr = Numstr & i:      Next   Else      For i = St To Ed:                Numstr = Numstr & i:      Next   End IfEnd Function

2006-07-11 01:01:13 補充:
tmp = IIf(i <> N, tmp & i & i, tmp & i)修改為↓tmp = IIf(i <> Val(N), tmp & i & i, tmp & i)If i > N Then i = N - 1: flag = False '// 印完上半部後改印下半部改為↓If i > Val(N) Then i = N - 1: flag = False '// 印完上半部後改印下半部把N的as integer拿掉後(因為寫了防呆),程式錯誤,真是找自己麻煩...

2006-07-12 22:20:55 補充:
Cls Dim i%, N%, j% N = Val(InputBox("輸入N")) a = 0: cnt = -3 For i = -N To N '上到下 If i = 0 Then i = 2: a = a - 2 K = a a = IIf(i < 0, a + 1, a - 1) cnt = IIf(i < 0, cnt + 2, cnt - 2)

2006-07-12 22:21:52 補充:
j_ed = IIf(i = N Or i = -N, Abs(i) * 2 - 1, Abs(i) * 2)
'j迴圈依序印左,空白,右
For j = 1 To j_ed
K = IIf(j <= Abs(i), K + 1, K - 1)
If j_ed = Abs(i) * 2 - 1 Then
Print K;
Else
Print IIf(j > Abs(i), K + 1, K);
End If

2006-07-12 22:21:59 補充:
If j = Abs(i) Then Print Spc(cnt * 2);
Next
Print
Next

2006-07-10 20:44:41 · answer #1 · answered by ? 6 · 0 0

月島大:
有沒有限定數字在10以下?超過10菱形會跑掉.

2006-07-12 17:32:25 補充:
'第1種方式(Print輸出)Private Sub Command1_Click()    Dim N%, I%, J%, S$, A%, M%, F%, T%, X%        Do      N = Int(Val(InputBox("請輸入>1的整數", , 5)))    Loop Until N > 1    FontName = "細明體": AutoRedraw = True    Cls    F = 1: T = N * 2 - 1: X = 1    For I = 1 To N * 2 - 1        For J = F To T Step X            If J > N Then              A = N - J Mod N + M              Print IIf(A > N, " ", CStr(A));            Else              Print IIf(J + M > N, " ", CStr(J + M));            End If        Next        If I = N Then T = 1: F = N * 2 - 1: X = -1        M = M + X        Print    NextEnd Sub'第2種方式(Label輸出)Private Sub Command2_Click()    Dim N%, I%, J%, X#, H#, W#, V%, Y%    Static K%        Do      N = Int(Val(InputBox("請輸入>1的整數", , 5)))    Loop Until N > 1        If K Then       For I = 0 To K           Controls.Remove "F" & I       Next    End If        K = N * 4 - 3    ReDim F(K) As Label    X = 1: Y = 1    For I = 0 To K        If I = N * 2 Then Y = -1: X = N - 1        Set F(I) = Controls.Add("VB.Label", "F" & I)        With F(I)              .BackStyle = 0: .Visible = True             If I Mod 2 Then                For J = X To N                    F(I) = J & F(I)                Next                .Alignment = 1                .Move W - Me.TextWidth(CStr(N)), H, W, V                H = H + .Height                X = X + Y             Else                For J = X To N                    F(I) = F(I) & J                Next                If I = 0 Then                   .AutoSize = True                   W = .Width: V = .Height                End If                .Move 0, H, W, V             End If        End With   NextEnd Sub

2006-07-12 18:18:52 補充:
嘿嘿嘿...你都知道了還問,老婆不在當然就...

2006-07-12 13:32:25 · answer #2 · answered by W.J.S. 7 · 0 0

to W.J.S. 大
請想辦法做數字定位吧 ^^;
話說今天一整天都沒看到你....
該不會跑去匪類了吧 XD

2006-07-11 20:44:08 · answer #3 · answered by ? 5 · 0 0

'好題目,值得思考:)
'個人還是習慣把用到的變數宣告一下
'懶得加註解了,用的是展開的觀念
Dim N As Integer, NT As Integer
Dim i As Integer, j As Integer
Dim strT As String, strJ As String, strANS As String

N = 5 '請手動設定

For i = N - 1 To 0 Step -1

NT = N + i

strT = IIf(NT > N, " ", NT)

For j = NT - 1 To 1 + i Step -1

strJ = IIf(j > N, " ", j)
strT = strJ & strT & strJ

Next

strT = strT & vbNewLine
strANS = IIf(i = N - 1, strT, strT & strANS & strT)

Next

Print strANS '答案

2006-07-10 23:31:24 · answer #4 · answered by ? 4 · 0 0

fedest.com, questions and answers