在VB里利用循环嵌套结构,实现九九乘法表。

2025-02-06 05:41:34
推荐回答(3个)
回答1:

Dim X(1 To 9, 1 To 9)

Private Sub Command1_Click()
For I = 0 To 8
Label1(I).Caption = ""
Next I
For I = 1 To 9
Label1(0).Caption = Label1(0).Caption & " " & vbNewLine
For J = 1 To 9
If X(I, J) < 10 Then
Label1(0).Caption = Label1(0).Caption & " " & " " & X(I, J)
Else
Label1(0).Caption = Label1(0).Caption & " " & X(I, J)
End If
Next J
Next I
End Sub

Private Sub Command2_Click()
For I = 0 To 8
Label1(I).Caption = ""
Next I
For I = 1 To 9
Label1(0).Caption = Label1(0).Caption & " " & vbNewLine
For J = 1 To I
If X(I, J) < 10 Then
Label1(0).Caption = Label1(0).Caption & " " & " " & X(I, J)
Else
Label1(0).Caption = Label1(0).Caption & " " & X(I, J)
End If
Next J
Next I
End Sub

Private Sub Command3_Click()
For I = 0 To 8
Label1(I).Caption = ""
Next I
For I = 9 To 1 Step -1
Label1(0).Caption = Label1(0).Caption & " " & vbNewLine
For J = 1 To I
If X(I, J) < 10 Then
Label1(0).Caption = Label1(0).Caption & " " & " " & X(I, J)
Else
Label1(0).Caption = Label1(0).Caption & " " & X(I, J)
End If
Next J
Next I
End Sub

Private Sub Command4_Click()
For I = 0 To 8
Label1(I).Caption = ""
Next I
End Sub

Private Sub Form_Load()
Command1.Caption = "矩 阵 显 示"
Command2.Caption = "正三角显示"
Command3.Caption = "倒三角显示"
Command4.Caption = "清 除"
For I = 1 To 9
For J = 1 To 9
X(I, J) = I * J
Next J
Next I
End Sub

回答2:

Private Sub Form_Load()
Show
FontSize = 15
Print Tab(20); "九九乘法表"
Dim i As Integer
Dim j As Integer
Print
Print " *";

For i = 1 To 9
Print Tab(i * 6); i;
Next

For i = 1 To 9
Print
Print i; " ";
For j = i To 9
Print Tab(j * 6); i * j; " ";
Next j
Next i

End Sub

回答3:

不太理解你的意思 自己参考一下下面网页上的第三个问题吧
http://zhidao.baidu.com/question/25709682.html