VB期末考试的几道程序修改题目求解!!!

2024-11-22 00:59:57
推荐回答(1个)
回答1:

1.求输入任意两个数的最大公约数~!!
代码如下:Private Sub Command1_Click()
Dim m, n, s As Single
m = Val(Text1.Text)
n = Val(Text2.Text)
'下行已改正
Do While (n <> 0)
s = m Mod n
m = n
n = s
Loop
'下行已改正
Text3.Text = m

End Sub

Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
2.输出100到1000以内的所有水仙花数
Private Sub Command1_Click()
Dim a, b, c
For i = 100 To 999
a = Int(i / 100)
'下行已改正
b = Int((i - a * 100) / 10)
c = i Mod 10
If a * 100 + b * 10 + c = a ^ 3 + b ^ 3 + c ^ 3 Then
'下行已改正
Print a * 100 + b * 10 + c
Print
End If
Next i
End Sub

Private Sub Command2_Click()
End
End Sub
3.设计程序,计算出S=1*(1*2)*(1*2*3)*.....*(1*2*3*....*n)的积

Private Sub Command1_Click()
Dim n As Integer, i As Integer, j As Long, s As Long
n = Val(Text1.Text)
'下行已改正
j = 1
s = 1
For i = 1 To n
j = j * i
'下行已改正
s = s * j
Next i
Text2.Text = s
End Sub