2012年11月6日 星期二

九九乘法


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

4 則留言:

  1. Dim showw As String
    Dim havedo As Boolean
    Private Sub Form_Load()
    Me.Hide

    Open App.Path & "\out.txt" For Output As #2
    For ii = 1 To 9
    For iii = 1 To ii
    showw = Str(ii * iii)
    showw = Replace(showw, " ", "")
    If Len(showw) = 1 Then showw = " " & showw
    If Len(showw) = 2 Then showw = " " & showw
    Print #2, showw;
    Next
    Print #2,
    Next
    Close #2

    End
    End Sub

    回覆刪除
  2. Dim showw As String
    Dim havedo As Boolean
    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, num
    For ii = 1 To num
    For iii = 1 To ii
    showw = Str(ii * iii)
    showw = Replace(showw, " ", "")
    If Len(showw) = 1 Then showw = " " & showw
    If Len(showw) = 2 Then showw = " " & showw
    Print #2, showw;
    Next
    Print #2,
    Next
    Close #2
    Close #1

    End
    End Sub

    回覆刪除

  3. 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
    a = j * i
    If a < 10 Then
    Print #2, Space(2) & a;
    Else
    Print #2, Space(1) & a;
    End If
    Next
    Print #2, ""
    Next
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  4. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\out.txt" For Output As #2
    For i = 1 To 9
    For j = 1 To i
    n = i * j
    If n < 10 Then
    Print #2, Space(2) & n;
    Else
    Print #2, Space(1) & n;
    End If
    Next
    Print #2,
    Next
    Close
    End
    End Sub

    回覆刪除