求高手帮做VB程序题 谢谢啊

2024年11月19日 01:19
有2个网友回答
网友(1):

第一题
Private Sub Command1_Click()
Dim s As Integer, n As Integer, sum As Integer, i As Integer
sum = 1
s = InputBox("输入S值", "提示")
For i = 1 To s
sum = sum * i
If sum > s Then
n = i - 1
Print "最大的n值", n
Exit For
End If
Next
End Sub

第二题
Private Sub Command1_Click()
Dim n As Integer, i As Integer
n = InputBox("键入N值", "提示")
For i = 1 To n
If i Mod 7 = 0 Then
Print i
End If
Next i
End Sub

第三题
Private Sub Command1_Click()
n = InputBox("键入一个数值0-99999")
Text1.Text = "这个数字是" & Len(n) & "位数"
End Sub

第四题
Private Sub Command1_Click()
For i = 1 To 100
For j = 1 To i
If Int(Sqr(i - j)) = Sqr(i - j) And Int(Sqr(i + j)) = Sqr(i + j) Then

Print j; "和"; i; "是自然数对"
End If
Next
Next
End Sub

你只需添加一个命令按钮就行

网友(2):

1
Private Sub Command1_Click()
a = Val(InputBox("S值=", "输入"))
s = 1
For i = 1 To a
s = s * i
If s > a Then
Exit For
End If
Next
MsgBox "N值为" + Str(i)
End Sub

2
Private Sub Command1_Click()

N = InputBox("输入N值", "输入")
For i = 1 To N
If (i Mod 7) = 0 Then
S = S + i
End If
Next
MsgBox "和为" + Str(S)
End Sub

3
Private Sub Command1_Click()
MsgBox Str(Len(Text1.Text)) + "位数"
End Sub

Private Sub Form_Load()
Text1.MaxLength = 5
End Sub

4
Private Sub Command1_Click()
For x = 1 To 100
For y = x To 100
a = x + y
b = Abs(x - y)
If Sqr(a) = Fix(Sqr(a)) And Sqr(b) = Fix(Sqr(b)) Then
Print x, y
End If
Next
Next
End Sub