2011年2月10日 星期四

九九乘法




請由"in.txt"中讀取一整數N(1<=N<=9),利用迴圈配合條件指令,印出九九乘法表的前N列至"out.txt"。
※請注意垂直對齊

9 則留言:

  1. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2

    Input #1, N

    For i = 1 To N
    For j = 1 To i
    ans = i * j
    If Len(ans) <> 2 Then ans = " " & ans
    Print #2, " " & ans;
    Next
    Print #2, ""
    Next


    Close #1
    Close #2
    End
    End Sub


    -----------
    這個春節到台東去玩 ~

    昨晚才到家

    嗯...進度嚴重落後

    回覆刪除
  2. arro好,
    (我也終於又用筆電回復,比用ipad回復,容易多了)。
    這題OK。

    另外,其它的人,加油啊。實力與耐力是需要累積的。

    熊掌

    回覆刪除
  3. Dim N As Byte

    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Input #1, N
    Close #1

    Open App.Path & "\out.txt" For Output As #2

    For i = 1 To N
    If Len(i) <> 2 Then Print #2, " ";
    Print #2, i;
    For j = 1 To (i - 1)
    If Len(i * (j + 1)) <> 2 Then Print #2, " ";
    Print #2, i * (j + 1);
    Next j
    Print #2,
    Next i

    Close #2

    End
    End Sub


    要加油了我!!

    回覆刪除
  4. 佑好,
    程式ok.
    你們兩個都是用len這個函數來測長度,是可以。但是,直接拿來和10相比,就可以了。

    回覆刪除
  5. Private Sub Form_Load()
    Me.Hide

    Open App.Path & "\out.txt" For Output As #2
    Open App.Path & "\in.txt" For Input As #1

    Input #1, x

    For i = 1 To x

    For j = 1 To i

    Print #2, i * j;

    Next j

    Print #2,

    Next i

    Close #1
    Close #2
    End
    End Sub

    回覆刪除
  6. 緣尉~

    注意輸出的"空格"

    你的結果跟範例的空格位置不一樣噢

    (想說你的居然比我的簡潔)

    回覆刪除
  7. Private Sub Form_Load()
    Me.Hide

    Open App.Path & "\out.txt" For Output As #2
    Open App.Path & "\in.txt" For Input As #1

    Input #1, x

    For i = 1 To x

    For j = 1 To i

    If (i * j) < 10 Then
    Print #2, " " & i * j;
    Else
    Print #2, " " & i * j;
    End If

    Next j

    Print #2,

    Next i

    Close #1
    Close #2
    End
    End Sub
    -------------------
    謝謝Arro~
    這樣算不算硬性扭曲結果XD?

    回覆刪除
  8. 緣尉好,
    還是有錯哦,你的then 跟 else兩個內容是一樣的。

    回覆刪除
  9. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, t
    For i = 1 To t
    For j = 1 To i
    Print #2, i * j & " ";
    Next
    Print #2, ""
    Next
    Close
    Close
    End
    End Sub

    1:17

    回覆刪除